Skip to content

Commit 053d140

Browse files
committed
---
yaml --- r: 42719 b: refs/heads/try c: c75cc0a h: refs/heads/master i: 42717: 3cda823 42715: ac8c9d7 42711: c53497b 42703: db7576d 42687: c13dcf9 v: v3
1 parent 1e9fe50 commit 053d140

File tree

6 files changed

+134
-50
lines changed

6 files changed

+134
-50
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: 8eaf0737b75d7984a72bfd4393b4c1a9ab0a88e6
5+
refs/heads/try: c75cc0aa1073ca91825d6513b9b23068a2a69f5a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/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(&~"url") {
469-
Some(&json::String(u)) => copy u,
468+
let mut url = match j.find_copy(&~"url") {
469+
Some(json::String(u)) => u,
470470
_ => fail ~"needed 'url' field in source"
471471
};
472-
let method = match j.find(&~"method") {
473-
Some(&json::String(u)) => copy u,
472+
let method = match j.find_copy(&~"method") {
473+
Some(json::String(u)) => u,
474474
_ => assume_source_method(url)
475475
};
476-
let key = match j.find(&~"key") {
477-
Some(&json::String(u)) => Some(copy u),
476+
let key = match j.find_copy(&~"key") {
477+
Some(json::String(u)) => Some(u),
478478
_ => None
479479
};
480-
let keyfp = match j.find(&~"keyfp") {
481-
Some(&json::String(u)) => Some(copy u),
480+
let keyfp = match j.find_copy(&~"keyfp") {
481+
Some(json::String(u)) => Some(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(&~"name") {
516-
Some(&json::String(n)) => {
515+
let name = match p.find_copy(&~"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(&~"uuid") {
533-
Some(&json::String(n)) => {
532+
let uuid = match p.find_copy(&~"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-
copy n
540+
n
541541
}
542542
_ => {
543543
warn(~"malformed source json: " + src.name + ~" (missing uuid)");
544544
return;
545545
}
546546
};
547547

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

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

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

570570
let mut tags = ~[];
571-
match p.find(&~"tags") {
572-
Some(&json::List(js)) => {
571+
match p.find_copy(&~"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(&~"description") {
584-
Some(&json::String(n)) => copy n,
583+
let description = match p.find_copy(&~"description") {
584+
Some(json::String(n)) => n,
585585
_ => {
586586
warn(~"malformed source json: " + src.name
587587
+ ~" (missing description)");

branches/try/src/libcore/hashmap.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,24 @@ 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+
392410
impl<K: Hash IterBytes Eq, V: Eq> LinearMap<K, V>: Eq {
393411
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
394412
if self.len() != other.len() { return false; }
@@ -542,8 +560,8 @@ pub mod test {
542560
}
543561
assert m.len() == 0;
544562
assert m2.len() == 2;
545-
assert m2.get(&1) == &2;
546-
assert m2.get(&2) == &3;
563+
assert m2.find_copy(&1) == Some(2);
564+
assert m2.find_copy(&2) == Some(3);
547565
}
548566

549567
#[test]

branches/try/src/libstd/treemap.rs

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ use core::prelude::*;
2828

2929
// range search - O(log n) retrieval of an iterator from some key
3030

31-
// implement Ord for TreeSet
32-
// could be superset/subset-based or in-order lexicographic comparison... but
33-
// there are methods for is_superset/is_subset so lexicographic is more useful
34-
3531
// (possibly) implement the overloads Python does for sets:
3632
// * union: |
3733
// * intersection: &
@@ -71,6 +67,45 @@ impl <K: Eq Ord, V: Eq> TreeMap<K, V>: Eq {
7167
pure fn ne(&self, other: &TreeMap<K, V>) -> bool { !self.eq(other) }
7268
}
7369

70+
// Lexicographical comparison
71+
pure fn lt<K: Ord, V>(a: &TreeMap<K, V>, b: &TreeMap<K, V>) -> bool {
72+
let mut x = a.iter();
73+
let mut y = b.iter();
74+
75+
let (a_len, b_len) = (a.len(), b.len());
76+
for uint::min(a_len, b_len).times {
77+
unsafe { // purity workaround
78+
x = x.next();
79+
y = y.next();
80+
let (key_a,_) = x.get().unwrap();
81+
let (key_b,_) = y.get().unwrap();
82+
if *key_a < *key_b { return true; }
83+
if *key_a > *key_b { return false; }
84+
}
85+
};
86+
87+
return a_len < b_len;
88+
}
89+
90+
impl <K: Ord, V> TreeMap<K, V>: Ord {
91+
#[inline(always)]
92+
pure fn lt(&self, other: &TreeMap<K, V>) -> bool {
93+
lt(self, other)
94+
}
95+
#[inline(always)]
96+
pure fn le(&self, other: &TreeMap<K, V>) -> bool {
97+
!lt(other, self)
98+
}
99+
#[inline(always)]
100+
pure fn ge(&self, other: &TreeMap<K, V>) -> bool {
101+
!lt(self, other)
102+
}
103+
#[inline(always)]
104+
pure fn gt(&self, other: &TreeMap<K, V>) -> bool {
105+
lt(other, self)
106+
}
107+
}
108+
74109
impl <K: Ord, V> TreeMap<K, V>: Container {
75110
/// Return the number of elements in the map
76111
pure fn len(&self) -> uint { self.length }
@@ -220,6 +255,17 @@ impl <T: Eq Ord> TreeSet<T>: Eq {
220255
pure fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
221256
}
222257

258+
impl <T: Ord> TreeSet<T>: Ord {
259+
#[inline(always)]
260+
pure fn lt(&self, other: &TreeSet<T>) -> bool { self.map < other.map }
261+
#[inline(always)]
262+
pure fn le(&self, other: &TreeSet<T>) -> bool { self.map <= other.map }
263+
#[inline(always)]
264+
pure fn ge(&self, other: &TreeSet<T>) -> bool { self.map >= other.map }
265+
#[inline(always)]
266+
pure fn gt(&self, other: &TreeSet<T>) -> bool { self.map > other.map }
267+
}
268+
223269
impl <T: Ord> TreeSet<T>: Container {
224270
/// Return the number of elements in the set
225271
pure fn len(&self) -> uint { self.map.len() }
@@ -878,6 +924,38 @@ mod test_treemap {
878924
assert a == b;
879925
}
880926

927+
#[test]
928+
fn test_lt() {
929+
let mut a = TreeMap::new();
930+
let mut b = TreeMap::new();
931+
932+
assert !(a < b) && !(b < a);
933+
assert b.insert(0, 5);
934+
assert a < b;
935+
assert a.insert(0, 7);
936+
assert !(a < b) && !(b < a);
937+
assert b.insert(-2, 0);
938+
assert b < a;
939+
assert a.insert(-5, 2);
940+
assert a < b;
941+
assert a.insert(6, 2);
942+
assert a < b && !(b < a);
943+
}
944+
945+
#[test]
946+
fn test_ord() {
947+
let mut a = TreeMap::new();
948+
let mut b = TreeMap::new();
949+
950+
assert a <= b && a >= b;
951+
assert a.insert(1, 1);
952+
assert a > b && a >= b;
953+
assert b < a && b <= a;
954+
assert b.insert(2, 2);
955+
assert b > a && b >= a;
956+
assert a < b && a <= b;
957+
}
958+
881959
#[test]
882960
fn test_lazy_iterator() {
883961
let mut m = TreeMap::new();

branches/try/src/libstd/workcache.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,15 @@ 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-
}
182170

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

branches/try/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(&key)
26+
match table.find_copy(&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)