about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-09-19 16:55:01 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-09-19 17:03:01 -0700
commitcfed923600e2f7ad34241501200d595abccdeb54 (patch)
treed382eb144026703d9abee0e6a99b87b34e9bd138 /src/libcore
parent1c39f1968c77a3d42b0fdb30a36cff4d94a17da2 (diff)
demode the each() method on vec and other iterables.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/dlist.rs2
-rw-r--r--src/libcore/dvec.rs2
-rw-r--r--src/libcore/iter-trait.rs2
-rw-r--r--src/libcore/iter-trait/dlist.rs4
-rw-r--r--src/libcore/iter-trait/dvec.rs2
-rw-r--r--src/libcore/iter-trait/option.rs4
-rw-r--r--src/libcore/iter.rs32
-rw-r--r--src/libcore/os.rs2
-rw-r--r--src/libcore/path.rs16
-rw-r--r--src/libcore/vec.rs4
10 files changed, 37 insertions, 33 deletions
diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs
index d0474673f83..7f4a42db641 100644
--- a/src/libcore/dlist.rs
+++ b/src/libcore/dlist.rs
@@ -678,7 +678,7 @@ mod tests {
         let mut x = 0;
         for l.each |i| {
             x += 1;
-            if (i == 3) { break; }
+            if (*i == 3) { break; }
         }
         assert x == 3;
     }
diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs
index 482a326b74f..8f196b9e078 100644
--- a/src/libcore/dvec.rs
+++ b/src/libcore/dvec.rs
@@ -272,7 +272,7 @@ impl<A: Copy> DVec<A> {
             }
            };
 
-        for ts.each |t| { vec::push(v, t) };
+        for ts.each |t| { vec::push(v, *t) };
            v
         }
     }
diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs
index 27b525cba90..2bc79d20bd3 100644
--- a/src/libcore/iter-trait.rs
+++ b/src/libcore/iter-trait.rs
@@ -7,7 +7,7 @@ use inst::{IMPL_T, EACH, SIZE_HINT};
 export extensions;
 
 impl<A> IMPL_T<A>: iter::BaseIter<A> {
-    pure fn each(blk: fn(A) -> bool) { EACH(self, blk) }
+    pure fn each(blk: fn(v: &A) -> bool) { EACH(self, blk) }
     pure fn size_hint() -> Option<uint> { SIZE_HINT(self) }
 }
 
diff --git a/src/libcore/iter-trait/dlist.rs b/src/libcore/iter-trait/dlist.rs
index ae6265409ca..fde6cf22a5e 100644
--- a/src/libcore/iter-trait/dlist.rs
+++ b/src/libcore/iter-trait/dlist.rs
@@ -8,12 +8,12 @@ type IMPL_T<A> = dlist::DList<A>;
  * e.g. breadth-first search with in-place enqueues), but removing the current
  * node is forbidden.
  */
-pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
+pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
     let mut link = self.peek_n();
     while option::is_some(link) {
         let nobe = option::get(link);
         assert nobe.linked;
-        if !f(nobe.data) { break; }
+        if !f(&nobe.data) { break; }
         // Check (weakly) that the user didn't do a remove.
         if self.size == 0 {
             fail ~"The dlist became empty during iteration??"
diff --git a/src/libcore/iter-trait/dvec.rs b/src/libcore/iter-trait/dvec.rs
index 7284d02d3ac..0f51df7b545 100644
--- a/src/libcore/iter-trait/dvec.rs
+++ b/src/libcore/iter-trait/dvec.rs
@@ -6,7 +6,7 @@ type IMPL_T<A> = dvec::DVec<A>;
  *
  * Attempts to access this dvec during iteration will fail.
  */
-pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
+pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
     unsafe {
         do self.swap |v| {
             v.each(f);
diff --git a/src/libcore/iter-trait/option.rs b/src/libcore/iter-trait/option.rs
index 206efa85064..e1ffec0a7d7 100644
--- a/src/libcore/iter-trait/option.rs
+++ b/src/libcore/iter-trait/option.rs
@@ -1,10 +1,10 @@
 #[allow(non_camel_case_types)]
 type IMPL_T<A> = Option<A>;
 
-pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
+pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
     match self {
       None => (),
-      Some(a) => { f(a); }
+      Some(ref a) => { f(a); }
     }
 }
 
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index 7bc356ce812..aab6bc38d93 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -10,7 +10,7 @@ use cmp::{Eq, Ord};
 type InitOp<T> = fn(uint) -> T;
 
 trait BaseIter<A> {
-    pure fn each(blk: fn(A) -> bool);
+    pure fn each(blk: fn(v: &A) -> bool);
     pure fn size_hint() -> Option<uint>;
 }
 
@@ -69,21 +69,21 @@ trait Buildable<A> {
 pure fn eachi<A,IA:BaseIter<A>>(self: IA, blk: fn(uint, A) -> bool) {
     let mut i = 0u;
     for self.each |a| {
-        if !blk(i, a) { break; }
+        if !blk(i, *a) { break; }
         i += 1u;
     }
 }
 
 pure fn all<A,IA:BaseIter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
     for self.each |a| {
-        if !blk(a) { return false; }
+        if !blk(*a) { return false; }
     }
     return true;
 }
 
 pure fn any<A,IA:BaseIter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
     for self.each |a| {
-        if blk(a) { return true; }
+        if blk(*a) { return true; }
     }
     return false;
 }
@@ -92,7 +92,7 @@ pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: IA,
                                          prd: fn(A) -> bool) -> ~[A] {
     do vec::build_sized_opt(self.size_hint()) |push| {
         for self.each |a| {
-            if prd(a) { push(a); }
+            if prd(*a) { push(*a); }
         }
     }
 }
@@ -101,7 +101,7 @@ pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
     -> ~[B] {
     do vec::build_sized_opt(self.size_hint()) |push| {
         for self.each |a| {
-            push(op(a));
+            push(op(*a));
         }
     }
 }
@@ -111,8 +111,8 @@ pure fn flat_map_to_vec<A:Copy,B:Copy,IA:BaseIter<A>,IB:BaseIter<B>>(
 
     do vec::build |push| {
         for self.each |a| {
-            for op(a).each |b| {
-                push(b);
+            for op(*a).each |b| {
+                push(*b);
             }
         }
     }
@@ -121,7 +121,7 @@ pure fn flat_map_to_vec<A:Copy,B:Copy,IA:BaseIter<A>,IB:BaseIter<B>>(
 pure fn foldl<A,B,IA:BaseIter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
     let mut b <- b0;
     for self.each |a| {
-        b = blk(b, a);
+        b = blk(b, *a);
     }
     move b
 }
@@ -132,7 +132,7 @@ pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
 
 pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> bool {
     for self.each |a| {
-        if a == x { return true; }
+        if *a == x { return true; }
     }
     return false;
 }
@@ -152,7 +152,7 @@ pure fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool)
 {
     let mut i = 0;
     for self.each |a| {
-        if f(a) { return Some(i); }
+        if f(*a) { return Some(i); }
         i += 1;
     }
     return None;
@@ -205,7 +205,7 @@ pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
 pure fn find<A: Copy,IA:BaseIter<A>>(self: IA,
                                      p: fn(A) -> bool) -> Option<A> {
     for self.each |i| {
-        if p(i) { return Some(i) }
+        if p(*i) { return Some(*i) }
     }
     return None;
 }
@@ -254,7 +254,7 @@ pure fn build_sized_opt<A,B: Buildable<A>>(
 fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: IT, f: fn(T) -> U) -> BU {
     do build_sized_opt(v.size_hint()) |push| {
         for v.each() |elem| {
-            push(f(elem));
+            push(f(*elem));
         }
     }
 }
@@ -292,8 +292,8 @@ pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
     let size_opt = lhs.size_hint().chain(
         |sz1| rhs.size_hint().map(|sz2| sz1+sz2));
     do build_sized_opt(size_opt) |push| {
-        for lhs.each |x| { push(x); }
-        for rhs.each |x| { push(x); }
+        for lhs.each |x| { push(*x); }
+        for rhs.each |x| { push(*x); }
     }
 }
 
@@ -303,6 +303,6 @@ pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
 pure fn copy_seq<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
     v: IT) -> BT {
     do build_sized_opt(v.size_hint()) |push| {
-        for v.each |x| { push(x); }
+        for v.each |x| { push(*x); }
     }
 }
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 6c6186459ac..21a6a06572a 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -529,7 +529,7 @@ fn walk_dir(p: &Path, f: fn((&Path)) -> bool) {
     fn walk_dir_(p: &Path, f: fn((&Path)) -> bool) -> bool {
         let mut keepgoing = true;
         do list_dir(p).each |q| {
-            let path = &p.push(q);
+            let path = &p.push(*q);
             if !f(path) {
                 keepgoing = false;
                 false
diff --git a/src/libcore/path.rs b/src/libcore/path.rs
index 80dfab3fbef..88d2526f310 100644
--- a/src/libcore/path.rs
+++ b/src/libcore/path.rs
@@ -203,7 +203,9 @@ impl PosixPath : GenericPath {
     pure fn push_many(cs: &[~str]) -> PosixPath {
         let mut v = copy self.components;
         for cs.each |e| {
-            let mut ss = str::split_nonempty(e, |c| windows::is_sep(c as u8));
+            let mut ss = str::split_nonempty(
+                *e,
+                |c| windows::is_sep(c as u8));
             unsafe { vec::push_all_move(v, move ss); }
         }
         PosixPath { components: move v, ..self }
@@ -395,7 +397,9 @@ impl WindowsPath : GenericPath {
     pure fn push_many(cs: &[~str]) -> WindowsPath {
         let mut v = copy self.components;
         for cs.each |e| {
-            let mut ss = str::split_nonempty(e, |c| windows::is_sep(c as u8));
+            let mut ss = str::split_nonempty(
+                *e,
+                |c| windows::is_sep(c as u8));
             unsafe { vec::push_all_move(v, move ss); }
         }
         return WindowsPath { components: move v, ..self }
@@ -430,13 +434,13 @@ pure fn normalize(components: &[~str]) -> ~[~str] {
     unsafe {
         for components.each |c| {
             unsafe {
-                if c == ~"." && components.len() > 1 { loop; }
-                if c == ~"" { loop; }
-                if c == ~".." && cs.len() != 0 {
+                if *c == ~"." && components.len() > 1 { loop; }
+                if *c == ~"" { loop; }
+                if *c == ~".." && cs.len() != 0 {
                     vec::pop(cs);
                     loop;
                 }
-                vec::push(cs, copy c);
+                vec::push(cs, copy *c);
             }
         }
     }
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index c81baf52476..2fac80aa2e7 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -1874,9 +1874,9 @@ mod bytes {
 // required in the slice.
 
 impl<A> &[A]: iter::BaseIter<A> {
-    pure fn each(blk: fn(A) -> bool) {
+    pure fn each(blk: fn(v: &A) -> bool) {
         for each(self) |e| {
-            if (!blk(*e)) {
+            if (!blk(e)) {
                 return;
             }
         }