Skip to content

Commit 63e5a9b

Browse files
committed
---
yaml --- r: 54612 b: refs/heads/snap-stage3 c: 24eee52 h: refs/heads/master v: v3
1 parent 0068968 commit 63e5a9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+534
-1162
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 3322595e896e95c3e19ca33c854ad529f2ef3c19
4+
refs/heads/snap-stage3: 24eee5296bd8ec29285f65ef180d9cc9a9a391bf
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/cmp.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,6 @@ totalord_impl!(i64)
116116
totalord_impl!(int)
117117
totalord_impl!(uint)
118118

119-
pub fn cmp2<A:TotalOrd,B:TotalOrd>(
120-
a1: &A, b1: &B,
121-
a2: &A, b2: &B) -> Ordering
122-
{
123-
//! Compares (a1, b1) against (a2, b2), where the a values are more significant.
124-
125-
match a1.cmp(a2) {
126-
Less => Less,
127-
Greater => Greater,
128-
Equal => b1.cmp(b2)
129-
}
130-
}
131-
132119
/**
133120
* Trait for values that can be compared for a sort-order.
134121
*
@@ -206,14 +193,6 @@ mod test {
206193
assert_eq!(12.cmp(-5), Greater);
207194
}
208195

209-
#[test]
210-
fn test_cmp2() {
211-
assert_eq!(cmp2(1, 2, 3, 4), Less);
212-
assert_eq!(cmp2(3, 2, 3, 4), Less);
213-
assert_eq!(cmp2(5, 2, 3, 4), Greater);
214-
assert_eq!(cmp2(5, 5, 5, 4), Greater);
215-
}
216-
217196
#[test]
218197
fn test_int_totaleq() {
219198
assert!(5.equals(&5));

branches/snap-stage3/src/libcore/container.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub trait Map<K, V>: Mutable {
2929
/// Return true if the map contains a value for the specified key
3030
fn contains_key(&self, key: &K) -> bool;
3131

32-
// Visits all keys and values
33-
fn each(&self, f: &fn(&K, &V) -> bool);
34-
3532
/// Visit all keys
3633
fn each_key(&self, f: &fn(&K) -> bool);
3734

branches/snap-stage3/src/libcore/hashmap.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,24 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
279279
}
280280
}
281281
282+
impl<'self,K:Hash + IterBytes + Eq,V>
283+
BaseIter<(&'self K, &'self V)> for HashMap<K, V> {
284+
/// Visit all key-value pairs
285+
fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
286+
for uint::range(0, self.buckets.len()) |i| {
287+
let mut broke = false;
288+
do self.buckets[i].map |bucket| {
289+
if !blk(&(&bucket.key, &bucket.value)) {
290+
broke = true; // FIXME(#3064) just write "break;"
291+
}
292+
};
293+
if broke { break; }
294+
}
295+
}
296+
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
297+
}
298+
299+
282300
impl<K:Hash + IterBytes + Eq,V> Container for HashMap<K, V> {
283301
/// Return the number of elements in the map
284302
fn len(&const self) -> uint { self.size }
@@ -297,7 +315,7 @@ impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
297315
}
298316
}
299317
300-
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
318+
impl<'self,K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
301319
/// Return true if the map contains a value for the specified key
302320
fn contains_key(&self, k: &K) -> bool {
303321
match self.bucket_for_key(k) {
@@ -306,25 +324,14 @@ impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
306324
}
307325
}
308326
309-
/// Visit all key-value pairs
310-
fn each(&self, blk: &fn(&'self K, &'self V) -> bool) {
311-
for uint::range(0, self.buckets.len()) |i| {
312-
for self.buckets[i].each |bucket| {
313-
if !blk(&bucket.key, &bucket.value) {
314-
return;
315-
}
316-
}
317-
}
318-
}
319-
320327
/// Visit all keys
321328
fn each_key(&self, blk: &fn(k: &K) -> bool) {
322-
self.each(|k, _| blk(k))
329+
self.each(|&(k, _)| blk(k))
323330
}
324331
325332
/// Visit all values
326333
fn each_value(&self, blk: &fn(v: &V) -> bool) {
327-
self.each(|_, v| blk(v))
334+
self.each(|&(_, v)| blk(v))
328335
}
329336
330337
/// Iterate over the map and mutate the contained values
@@ -538,7 +545,7 @@ impl<K:Hash + IterBytes + Eq,V:Eq> Eq for HashMap<K, V> {
538545
fn eq(&self, other: &HashMap<K, V>) -> bool {
539546
if self.len() != other.len() { return false; }
540547

541-
for self.each |key, value| {
548+
for self.each |&(key, value)| {
542549
match other.find(key) {
543550
None => return false,
544551
Some(v) => if value != v { return false },
@@ -791,7 +798,7 @@ mod test_map {
791798
assert!(m.insert(i, i*2));
792799
}
793800
let mut observed = 0;
794-
for m.each |k, v| {
801+
for m.each |&(k, v)| {
795802
assert!(*v == *k * 2);
796803
observed |= (1 << *k);
797804
}

branches/snap-stage3/src/libcore/iter.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,29 @@ pub fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(v: &IT) -> BT {
344344
for v.each |x| { push(*x); }
345345
}
346346
}
347+
348+
/**
349+
* Helper function to transform an internal iterator into an owned vector.
350+
*
351+
* # Example:
352+
*
353+
* ~~~
354+
* let v = ~[1, 2, 3];
355+
* let v2 = do iter_to_vec |f| { v.each(|e| f(*e)) };
356+
* if v != v2 { fail!() }
357+
* ~~~
358+
*/
359+
#[inline(always)]
360+
pub fn iter_to_vec<T>(pusher: &fn(it: &fn(T) -> bool)) -> ~[T] {
361+
let mut v = ~[];
362+
let pushf = |e| {v.push(e); true};
363+
pusher(pushf);
364+
v
365+
}
366+
367+
#[test]
368+
fn test_iter_to_vec() {
369+
let v = ~[1, 2, 3];
370+
let v2 = do iter_to_vec |f| { v.each(|e| f(*e)) };
371+
if v != v2 { fail!() }
372+
}

branches/snap-stage3/src/libcore/str.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,7 @@ pub fn slice_shift_char<'a>(s: &'a str) -> (char, &'a str) {
301301

302302
/// Prepend a char to a string
303303
pub fn unshift_char(s: &mut ~str, ch: char) {
304-
// This could be more efficient.
305-
let mut new_str = ~"";
306-
new_str.push_char(ch);
307-
new_str.push_str(*s);
308-
*s = new_str;
304+
*s = from_char(ch) + *s;
309305
}
310306

311307
/**

branches/snap-stage3/src/libcore/trie.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ pub struct TrieMap<T> {
2828
priv length: uint
2929
}
3030

31+
impl<'self,T> BaseIter<(uint, &'self T)> for TrieMap<T> {
32+
/// Visit all key-value pairs in order
33+
#[inline(always)]
34+
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) {
35+
self.root.each(f);
36+
}
37+
#[inline(always)]
38+
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
39+
}
40+
41+
impl<'self,T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
42+
/// Visit all key-value pairs in reverse order
43+
#[inline(always)]
44+
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) {
45+
self.root.each_reverse(f);
46+
}
47+
}
48+
3149
impl<T> Container for TrieMap<T> {
3250
/// Return the number of elements in the map
3351
#[inline(always)]
@@ -54,22 +72,16 @@ impl<T> Map<uint, T> for TrieMap<T> {
5472
self.find(key).is_some()
5573
}
5674

57-
/// Visit all key-value pairs in order
58-
#[inline(always)]
59-
fn each(&self, f: &fn(&uint, &'self T) -> bool) {
60-
self.root.each(f);
61-
}
62-
6375
/// Visit all keys in order
6476
#[inline(always)]
6577
fn each_key(&self, f: &fn(&uint) -> bool) {
66-
self.each(|k, _| f(k))
78+
self.each(|&(k, _)| f(&k))
6779
}
6880

6981
/// Visit all values in order
7082
#[inline(always)]
7183
fn each_value(&self, f: &fn(&T) -> bool) {
72-
self.each(|_, v| f(v))
84+
self.each(|&(_, v)| f(v))
7385
}
7486

7587
/// Iterate over the map and mutate the contained values
@@ -136,22 +148,16 @@ pub impl<T> TrieMap<T> {
136148
TrieMap{root: TrieNode::new(), length: 0}
137149
}
138150

139-
/// Visit all key-value pairs in reverse order
140-
#[inline(always)]
141-
fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) {
142-
self.root.each_reverse(f);
143-
}
144-
145151
/// Visit all keys in reverse order
146152
#[inline(always)]
147153
fn each_key_reverse(&self, f: &fn(&uint) -> bool) {
148-
self.each_reverse(|k, _| f(k))
154+
self.each_reverse(|&(k, _)| f(&k))
149155
}
150156

151157
/// Visit all values in reverse order
152158
#[inline(always)]
153159
fn each_value_reverse(&self, f: &fn(&T) -> bool) {
154-
self.each_reverse(|_, v| f(v))
160+
self.each_reverse(|&(_, v)| f(v))
155161
}
156162
}
157163

@@ -233,22 +239,22 @@ impl<T> TrieNode<T> {
233239
}
234240

235241
impl<T> TrieNode<T> {
236-
fn each(&self, f: &fn(&uint, &'self T) -> bool) -> bool {
242+
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
237243
for uint::range(0, self.children.len()) |idx| {
238244
match self.children[idx] {
239245
Internal(ref x) => if !x.each(f) { return false },
240-
External(k, ref v) => if !f(&k, v) { return false },
246+
External(k, ref v) => if !f(&(k, v)) { return false },
241247
Nothing => ()
242248
}
243249
}
244250
true
245251
}
246252

247-
fn each_reverse(&self, f: &fn(&uint, &'self T) -> bool) -> bool {
253+
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
248254
for uint::range_rev(self.children.len(), 0) |idx| {
249255
match self.children[idx - 1] {
250256
Internal(ref x) => if !x.each_reverse(f) { return false },
251-
External(k, ref v) => if !f(&k, v) { return false },
257+
External(k, ref v) => if !f(&(k, v)) { return false },
252258
Nothing => ()
253259
}
254260
}
@@ -432,8 +438,8 @@ mod tests {
432438
assert!(m.insert(1, 2));
433439

434440
let mut n = 0;
435-
for m.each |k, v| {
436-
assert!(*k == n);
441+
for m.each |&(k, v)| {
442+
assert!(k == n);
437443
assert!(*v == n * 2);
438444
n += 1;
439445
}
@@ -448,11 +454,11 @@ mod tests {
448454
}
449455

450456
let mut n = uint::max_value - 9999;
451-
for m.each |k, v| {
457+
for m.each |&(k, v)| {
452458
if n == uint::max_value - 5000 { break }
453459
assert!(n < uint::max_value - 5000);
454460

455-
assert!(*k == n);
461+
assert!(k == n);
456462
assert!(*v == n / 2);
457463
n += 1;
458464
}
@@ -469,8 +475,8 @@ mod tests {
469475
assert!(m.insert(1, 2));
470476

471477
let mut n = 4;
472-
for m.each_reverse |k, v| {
473-
assert!(*k == n);
478+
for m.each_reverse |&(k, v)| {
479+
assert!(k == n);
474480
assert!(*v == n * 2);
475481
n -= 1;
476482
}
@@ -485,11 +491,11 @@ mod tests {
485491
}
486492

487493
let mut n = uint::max_value;
488-
for m.each_reverse |k, v| {
494+
for m.each_reverse |&(k, v)| {
489495
if n == uint::max_value - 5000 { break }
490496
assert!(n > uint::max_value - 5000);
491497

492-
assert!(*k == n);
498+
assert!(k == n);
493499
assert!(*v == n / 2);
494500
n -= 1;
495501
}

branches/snap-stage3/src/libcore/tuple.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl<A:Ord> Ord for (A,) {
161161
fn gt(&self, other: &(A,)) -> bool { other.lt(&(*self)) }
162162
}
163163

164+
164165
#[cfg(notest)]
165166
impl<A:Eq,B:Eq> Eq for (A, B) {
166167
#[inline(always)]

branches/snap-stage3/src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool {
8686

8787
pub fn iter_crate_data(cstore: &CStore,
8888
i: &fn(ast::crate_num, @crate_metadata)) {
89-
for cstore.metas.each |&k, &v| {
89+
for cstore.metas.each |&(&k, &v)| {
9090
i(k, v);
9191
}
9292
}

branches/snap-stage3/src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ fn parse_region(st: @mut PState) -> ty::Region {
239239
assert!(next(st) == '|');
240240
let br = parse_bound_region(st);
241241
assert!(next(st) == ']');
242-
ty::re_free(ty::FreeRegion {scope_id: id,
243-
bound_region: br})
242+
ty::re_free(id, br)
244243
}
245244
's' => {
246245
let id = parse_int(st);

branches/snap-stage3/src/librustc/metadata/tyencode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ fn enc_region(w: @io::Writer, cx: @ctxt, r: ty::Region) {
146146
w.write_char('b');
147147
enc_bound_region(w, cx, br);
148148
}
149-
ty::re_free(ref fr) => {
149+
ty::re_free(id, br) => {
150150
w.write_char('f');
151151
w.write_char('[');
152-
w.write_int(fr.scope_id);
152+
w.write_int(id);
153153
w.write_char('|');
154-
enc_bound_region(w, cx, fr.bound_region);
154+
enc_bound_region(w, cx, br);
155155
w.write_char(']');
156156
}
157157
ty::re_scope(nid) => {

branches/snap-stage3/src/librustc/middle/astencode.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,9 @@ impl tr for ty::Region {
475475
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::Region {
476476
match *self {
477477
ty::re_bound(br) => ty::re_bound(br.tr(xcx)),
478+
ty::re_free(id, br) => ty::re_free(xcx.tr_id(id), br.tr(xcx)),
478479
ty::re_scope(id) => ty::re_scope(xcx.tr_id(id)),
479480
ty::re_static | ty::re_infer(*) => *self,
480-
ty::re_free(ref fr) => {
481-
ty::re_free(ty::FreeRegion {scope_id: xcx.tr_id(fr.scope_id),
482-
bound_region: fr.bound_region.tr(xcx)})
483-
}
484481
}
485482
}
486483
}

0 commit comments

Comments
 (0)