Skip to content

Commit 2a48aef

Browse files
committed
Merge remote-tracking branch 'thestinger/hashmap' into deriving
2 parents c75cc0a + 8eaf073 commit 2a48aef

File tree

4 files changed

+45
-51
lines changed

4 files changed

+45
-51
lines changed

src/libcargo/cargo.rc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -465,20 +465,20 @@ fn parse_source(name: ~str, j: &json::Json) -> @Source {
465465

466466
match *j {
467467
json::Object(j) => {
468-
let mut url = match j.find_copy(&~"url") {
469-
Some(json::String(u)) => u,
468+
let mut url = match j.find(&~"url") {
469+
Some(&json::String(u)) => copy u,
470470
_ => fail ~"needed 'url' field in source"
471471
};
472-
let method = match j.find_copy(&~"method") {
473-
Some(json::String(u)) => u,
472+
let method = match j.find(&~"method") {
473+
Some(&json::String(u)) => copy u,
474474
_ => assume_source_method(url)
475475
};
476-
let key = match j.find_copy(&~"key") {
477-
Some(json::String(u)) => Some(u),
476+
let key = match j.find(&~"key") {
477+
Some(&json::String(u)) => Some(copy u),
478478
_ => None
479479
};
480-
let keyfp = match j.find_copy(&~"keyfp") {
481-
Some(json::String(u)) => Some(u),
480+
let keyfp = match j.find(&~"keyfp") {
481+
Some(&json::String(u)) => Some(copy u),
482482
_ => None
483483
};
484484
if method == ~"file" {
@@ -512,8 +512,8 @@ fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, @Source>) {
512512
}
513513

514514
fn load_one_source_package(src: @Source, p: &json::Object) {
515-
let name = match p.find_copy(&~"name") {
516-
Some(json::String(n)) => {
515+
let name = match p.find(&~"name") {
516+
Some(&json::String(n)) => {
517517
if !valid_pkg_name(n) {
518518
warn(~"malformed source json: "
519519
+ src.name + ~", '" + n + ~"'"+
@@ -529,47 +529,47 @@ fn load_one_source_package(src: @Source, p: &json::Object) {
529529
}
530530
};
531531

532-
let uuid = match p.find_copy(&~"uuid") {
533-
Some(json::String(n)) => {
532+
let uuid = match p.find(&~"uuid") {
533+
Some(&json::String(n)) => {
534534
if !is_uuid(n) {
535535
warn(~"malformed source json: "
536536
+ src.name + ~", '" + n + ~"'"+
537537
~" is an invalid uuid");
538538
return;
539539
}
540-
n
540+
copy n
541541
}
542542
_ => {
543543
warn(~"malformed source json: " + src.name + ~" (missing uuid)");
544544
return;
545545
}
546546
};
547547

548-
let url = match p.find_copy(&~"url") {
549-
Some(json::String(n)) => n,
548+
let url = match p.find(&~"url") {
549+
Some(&json::String(n)) => copy n,
550550
_ => {
551551
warn(~"malformed source json: " + src.name + ~" (missing url)");
552552
return;
553553
}
554554
};
555555

556-
let method = match p.find_copy(&~"method") {
557-
Some(json::String(n)) => n,
556+
let method = match p.find(&~"method") {
557+
Some(&json::String(n)) => copy n,
558558
_ => {
559559
warn(~"malformed source json: "
560560
+ src.name + ~" (missing method)");
561561
return;
562562
}
563563
};
564564

565-
let reference = match p.find_copy(&~"ref") {
566-
Some(json::String(n)) => Some(n),
565+
let reference = match p.find(&~"ref") {
566+
Some(&json::String(n)) => Some(copy n),
567567
_ => None
568568
};
569569

570570
let mut tags = ~[];
571-
match p.find_copy(&~"tags") {
572-
Some(json::List(js)) => {
571+
match p.find(&~"tags") {
572+
Some(&json::List(js)) => {
573573
for js.each |j| {
574574
match *j {
575575
json::String(ref j) => tags.grow(1u, j),
@@ -580,8 +580,8 @@ fn load_one_source_package(src: @Source, p: &json::Object) {
580580
_ => ()
581581
}
582582

583-
let description = match p.find_copy(&~"description") {
584-
Some(json::String(n)) => n,
583+
let description = match p.find(&~"description") {
584+
Some(&json::String(n)) => copy n,
585585
_ => {
586586
warn(~"malformed source json: " + src.name
587587
+ ~" (missing description)");

src/libcore/hashmap.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,6 @@ pub mod linear {
389389
}
390390
}
391391

392-
impl<K: Hash IterBytes Eq, V: Copy> LinearMap<K, V> {
393-
pure fn find_copy(&self, k: &K) -> Option<V> {
394-
match self.bucket_for_key(self.buckets, k) {
395-
FoundEntry(idx) => {
396-
// FIXME (#3148): Once we rewrite found_entry, this
397-
// failure case won't be necessary
398-
match self.buckets[idx] {
399-
Some(Bucket {value: copy value, _}) => {Some(value)}
400-
None => fail ~"LinearMap::find: internal logic error"
401-
}
402-
}
403-
TableFull | FoundHole(_) => {
404-
None
405-
}
406-
}
407-
}
408-
}
409-
410392
impl<K: Hash IterBytes Eq, V: Eq> LinearMap<K, V>: Eq {
411393
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
412394
if self.len() != other.len() { return false; }
@@ -560,8 +542,8 @@ pub mod test {
560542
}
561543
assert m.len() == 0;
562544
assert m2.len() == 2;
563-
assert m2.find_copy(&1) == Some(2);
564-
assert m2.find_copy(&2) == Some(3);
545+
assert m2.get(&1) == &2;
546+
assert m2.get(&2) == &3;
565547
}
566548

567549
#[test]

src/libstd/workcache.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,27 @@ struct Database {
167167
}
168168

169169
impl Database {
170+
#[cfg(stage0)]
171+
#[cfg(stage1)]
172+
fn prepare(&mut self, fn_name: &str,
173+
declared_inputs: &WorkMap) -> Option<(WorkMap, WorkMap, ~str)>
174+
{
175+
let k = json_encode(&(fn_name, declared_inputs));
176+
let db_cache = copy self.db_cache;
177+
match db_cache.find(&k) {
178+
None => None,
179+
Some(&v) => Some(json_decode(copy v))
180+
}
181+
}
170182

171-
fn prepare(&mut self,
172-
fn_name: &str,
173-
declared_inputs: &WorkMap) ->
174-
Option<(WorkMap, WorkMap, ~str)> {
183+
#[cfg(stage2)]
184+
fn prepare(&mut self, fn_name: &str,
185+
declared_inputs: &WorkMap) -> Option<(WorkMap, WorkMap, ~str)>
186+
{
175187
let k = json_encode(&(fn_name, declared_inputs));
176-
match self.db_cache.find_copy(&k) {
188+
match self.db_cache.find(&k) {
177189
None => None,
178-
Some(v) => Some(json_decode(v))
190+
Some(&v) => Some(json_decode(copy v))
179191
}
180192
}
181193

src/test/run-pass/issue-2804.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ enum object
2323

2424
fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str
2525
{
26-
match table.find_copy(&key)
26+
match table.find(&key)
2727
{
28-
option::Some(std::json::String(copy s)) =>
28+
option::Some(&std::json::String(copy s)) =>
2929
{
3030
copy s
3131
}

0 commit comments

Comments
 (0)