about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-06-29 02:08:32 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-06-30 21:15:24 +1000
commita890c2cbf1dd92d79ade5bd8f04142ae5511943f (patch)
tree4cb60f44f0f4d64d87f8a09937951adea5a8479d
parent45940ed988ab2d04e1dbecceef440071b04c11a9 (diff)
downloadrust-a890c2cbf1dd92d79ade5bd8f04142ae5511943f.tar.gz
rust-a890c2cbf1dd92d79ade5bd8f04142ae5511943f.zip
Convert vec::{rposition, rposition_elem, position_elem, contains} to methods.
-rw-r--r--src/libextra/smallintmap.rs10
-rw-r--r--src/librustc/metadata/cstore.rs3
-rw-r--r--src/librustc/middle/check_match.rs2
-rw-r--r--src/librustc/middle/ty.rs6
-rw-r--r--src/librustc/middle/typeck/check/mod.rs4
-rw-r--r--src/librustc/middle/typeck/infer/resolve.rs3
-rw-r--r--src/librustpkg/tests.rs12
-rw-r--r--src/libstd/hashmap.rs10
-rw-r--r--src/libstd/os.rs4
-rw-r--r--src/libstd/vec.rs68
-rw-r--r--src/test/bench/graph500-bfs.rs2
11 files changed, 50 insertions, 74 deletions
diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs
index e32c688da37..b07c05ad76a 100644
--- a/src/libextra/smallintmap.rs
+++ b/src/libextra/smallintmap.rs
@@ -383,8 +383,6 @@ mod test_set {
 
     use super::SmallIntSet;
 
-    use std::vec;
-
     #[test]
     fn test_disjoint() {
         let mut xs = SmallIntSet::new();
@@ -456,7 +454,7 @@ mod test_set {
         let mut i = 0;
         let expected = [3, 5, 11, 77];
         for a.intersection(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
@@ -479,7 +477,7 @@ mod test_set {
         let mut i = 0;
         let expected = [1, 5, 11];
         for a.difference(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
@@ -504,7 +502,7 @@ mod test_set {
         let mut i = 0;
         let expected = [1, 5, 11, 14, 22];
         for a.symmetric_difference(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
@@ -533,7 +531,7 @@ mod test_set {
         let mut i = 0;
         let expected = [1, 3, 5, 9, 11, 13, 16, 19, 24];
         for a.union(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs
index af5cc9136bd..3413cd341ba 100644
--- a/src/librustc/metadata/cstore.rs
+++ b/src/librustc/metadata/cstore.rs
@@ -17,7 +17,6 @@ use metadata::cstore;
 use metadata::decoder;
 
 use std::hashmap::HashMap;
-use std::vec;
 use extra;
 use syntax::ast;
 use syntax::parse::token::ident_interner;
@@ -91,7 +90,7 @@ pub fn iter_crate_data(cstore: &CStore,
 }
 
 pub fn add_used_crate_file(cstore: &mut CStore, lib: &Path) {
-    if !vec::contains(cstore.used_crate_files, lib) {
+    if !cstore.used_crate_files.contains(lib) {
         cstore.used_crate_files.push(copy *lib);
     }
 }
diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs
index ec5f5205760..c27b60477c0 100644
--- a/src/librustc/middle/check_match.rs
+++ b/src/librustc/middle/check_match.rs
@@ -363,7 +363,7 @@ pub fn missing_ctor(cx: &MatchCheckCtxt,
         for m.iter().advance |r| {
             let r = pat_ctor_id(cx, r[0]);
             for r.iter().advance |id| {
-                if !vec::contains(found, id) {
+                if !found.contains(id) {
                     found.push(/*bad*/copy *id);
                 }
             }
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index 4ed21d73f3e..8a6fff09c73 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -2323,7 +2323,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
                 false
             }
 
-            ty_struct(ref did, _) if vec::contains(*seen, did) => {
+            ty_struct(ref did, _) if seen.contains(did) => {
                 false
             }
 
@@ -2339,7 +2339,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
                 ts.iter().any_(|t| type_requires(cx, seen, r_ty, *t))
             }
 
-            ty_enum(ref did, _) if vec::contains(*seen, did) => {
+            ty_enum(ref did, _) if seen.contains(did) => {
                 false
             }
 
@@ -3266,7 +3266,7 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) {
     if !type_needs_infer(rt) { return; }
 
     // Occurs check!
-    if vec::contains(vars_in_type(rt), &vid) {
+    if vars_in_type(rt).contains(&vid) {
             // Maybe this should be span_err -- however, there's an
             // assertion later on that the type doesn't contain
             // variables, so in this case we have to be sure to die.
diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs
index f50b38e6f6c..d1edc1cd363 100644
--- a/src/librustc/middle/typeck/check/mod.rs
+++ b/src/librustc/middle/typeck/check/mod.rs
@@ -985,7 +985,7 @@ pub fn do_autoderef(fcx: @mut FnCtxt, sp: span, t: ty::t) -> (ty::t, uint) {
                 // concerned with this, as an error will be reported
                 // on the enum definition as well because the enum is
                 // not instantiable.
-                if vec::contains(enum_dids, did) {
+                if enum_dids.contains(did) {
                     return (t1, autoderefs);
                 }
                 enum_dids.push(*did);
@@ -3156,7 +3156,7 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
                   }
                 }
             }
-            if vec::contains(*disr_vals, &*disr_val) {
+            if disr_vals.contains(&*disr_val) {
                 ccx.tcx.sess.span_err(v.span,
                                       "discriminator value already exists");
             }
diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs
index 2326e2e10ef..941431ce0e3 100644
--- a/src/librustc/middle/typeck/infer/resolve.rs
+++ b/src/librustc/middle/typeck/infer/resolve.rs
@@ -57,7 +57,6 @@ use middle::typeck::infer::unify::{Root, UnifyInferCtxtMethods};
 use util::common::{indent, indenter};
 use util::ppaux::ty_to_str;
 
-use std::vec;
 use syntax::ast;
 
 pub static resolve_nested_tvar: uint = 0b0000000001;
@@ -204,7 +203,7 @@ impl ResolveState {
     }
 
     pub fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t {
-        if vec::contains(self.v_seen, &vid) {
+        if self.v_seen.contains(&vid) {
             self.err = Some(cyclic_ty(vid));
             return ty::mk_var(self.infcx.tcx, vid);
         } else {
diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs
index 0e2a4f33c72..697a9f53f1b 100644
--- a/src/librustpkg/tests.rs
+++ b/src/librustpkg/tests.rs
@@ -596,9 +596,9 @@ fn rust_path_contents() {
         let cwd = os::getcwd().push(".rust");
         let parent = cwd.pop().pop().push(".rust");
         let grandparent = cwd.pop().pop().pop().push(".rust");
-        assert!(vec::contains(p, &cwd));
-        assert!(vec::contains(p, &parent));
-        assert!(vec::contains(p, &grandparent));
+        assert!(p.contains(&cwd));
+        assert!(p.contains(&parent));
+        assert!(p.contains(&grandparent));
         for p.iter().advance() |a_path| {
             assert!(!a_path.components.is_empty());
         }
@@ -609,9 +609,9 @@ fn rust_path_contents() {
 fn rust_path_parse() {
     os::setenv("RUST_PATH", "/a/b/c:/d/e/f:/g/h/i");
     let paths = rust_path();
-    assert!(vec::contains(paths, &Path("/g/h/i")));
-    assert!(vec::contains(paths, &Path("/d/e/f")));
-    assert!(vec::contains(paths, &Path("/a/b/c")));
+    assert!(paths.contains(&Path("/g/h/i")));
+    assert!(paths.contains(&Path("/d/e/f")));
+    assert!(paths.contains(&Path("/a/b/c")));
     os::unsetenv("RUST_PATH");
 }
 
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index 35db229b65d..85dca1154bc 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -939,7 +939,7 @@ mod test_map {
 mod test_set {
     use super::*;
     use container::{Container, Map, Set};
-    use vec;
+    use vec::ImmutableEqVector;
     use uint;
 
     #[test]
@@ -1030,7 +1030,7 @@ mod test_set {
         let mut i = 0;
         let expected = [3, 5, 11, 77];
         for a.intersection(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
@@ -1053,7 +1053,7 @@ mod test_set {
         let mut i = 0;
         let expected = [1, 5, 11];
         for a.difference(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
@@ -1079,7 +1079,7 @@ mod test_set {
         let mut i = 0;
         let expected = [-2, 1, 5, 11, 14, 22];
         for a.symmetric_difference(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
@@ -1109,7 +1109,7 @@ mod test_set {
         let mut i = 0;
         let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24];
         for a.union(&b) |x| {
-            assert!(vec::contains(expected, x));
+            assert!(expected.contains(x));
             i += 1
         }
         assert_eq!(i, expected.len());
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 1fbcda12dce..6d13c662ee5 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -1544,10 +1544,10 @@ mod tests {
 
         let mut e = env();
         setenv(n, "VALUE");
-        assert!(!vec::contains(e, &(copy n, ~"VALUE")));
+        assert!(!e.contains(&(copy n, ~"VALUE")));
 
         e = env();
-        assert!(vec::contains(e, &(n, ~"VALUE")));
+        assert!(e.contains(&(n, ~"VALUE")));
     }
 
     #[test]
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index a704e604aa2..e2b0c54b9a4 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -220,9 +220,9 @@ pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
         match v.slice(start, ln).iter().position_(|t| f(t)) {
             None => break,
             Some(i) => {
-                result.push(v.slice(start, i).to_owned());
+                result.push(v.slice(start, start + i).to_owned());
                 // Make sure to skip the separator.
-                start = i + 1u;
+                start += i + 1u;
                 count -= 1u;
             }
         }
@@ -646,36 +646,6 @@ impl<'self, T:Copy> VectorVector<T> for &'self [&'self [T]] {
     }
 }
 
-/// Return true if a vector contains an element with the given value
-pub fn contains<T:Eq>(v: &[T], x: &T) -> bool {
-    for v.iter().advance |elt| { if *x == *elt { return true; } }
-    false
-}
-
-/// Find the first index containing a matching value
-pub fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
-    v.iter().position_(|y| *x == *y)
-}
-
-/// Find the last index containing a matching value
-pub fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
-    rposition(v, |y| *x == *y)
-}
-
-/**
- * Find the last index matching some predicate
- *
- * Apply function `f` to each element of `v` in reverse order.  When function
- * `f` returns true then an option containing the index is returned. If `f`
- * matches no elements then none is returned.
- */
-pub fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
-    for v.rev_iter().enumerate().advance |(i, t)| {
-        if f(t) { return Some(v.len() - i - 1); }
-    }
-    None
-}
-
 /**
  * Binary search a sorted vector with a comparator function.
  *
@@ -1265,11 +1235,14 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
      *
      * Apply function `f` to each element of `v` in reverse order.  When
      * function `f` returns true then an option containing the index is
-     * returned. If `f` matches no elements then none is returned.
+     * returned. If `f` matches no elements then None is returned.
      */
     #[inline]
     fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
-        rposition(*self, f)
+        for self.rev_iter().enumerate().advance |(i, t)| {
+            if f(t) { return Some(self.len() - i - 1); }
+        }
+        None
     }
 
     /// Apply a function to each element of a vector and return the results
@@ -1327,19 +1300,26 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
 pub trait ImmutableEqVector<T:Eq> {
     fn position_elem(&self, t: &T) -> Option<uint>;
     fn rposition_elem(&self, t: &T) -> Option<uint>;
+    fn contains(&self, x: &T) -> bool;
 }
 
 impl<'self,T:Eq> ImmutableEqVector<T> for &'self [T] {
     /// Find the first index containing a matching value
     #[inline]
     fn position_elem(&self, x: &T) -> Option<uint> {
-        position_elem(*self, x)
+        self.iter().position_(|y| *x == *y)
     }
 
     /// Find the last index containing a matching value
     #[inline]
     fn rposition_elem(&self, t: &T) -> Option<uint> {
-        rposition_elem(*self, t)
+        self.rposition(|x| *x == *t)
+    }
+
+    /// Return true if a vector contains an element with the given value
+    fn contains(&self, x: &T) -> bool {
+        for self.iter().advance |elt| { if *x == *elt { return true; } }
+        false
     }
 }
 
@@ -2838,13 +2818,13 @@ mod tests {
 
     #[test]
     fn test_position_elem() {
-        assert!(position_elem([], &1).is_none());
+        assert!([].position_elem(&1).is_none());
 
         let v1 = ~[1, 2, 3, 3, 2, 5];
-        assert_eq!(position_elem(v1, &1), Some(0u));
-        assert_eq!(position_elem(v1, &2), Some(1u));
-        assert_eq!(position_elem(v1, &5), Some(5u));
-        assert!(position_elem(v1, &4).is_none());
+        assert_eq!(v1.position_elem(&1), Some(0u));
+        assert_eq!(v1.position_elem(&2), Some(1u));
+        assert_eq!(v1.position_elem(&5), Some(5u));
+        assert!(v1.position_elem(&4).is_none());
     }
 
     #[test]
@@ -2853,8 +2833,8 @@ mod tests {
         fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
         let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
 
-        assert_eq!(rposition(v, f), Some(3u));
-        assert!(rposition(v, g).is_none());
+        assert_eq!(v.rposition(f), Some(3u));
+        assert!(v.rposition(g).is_none());
     }
 
     #[test]
@@ -3417,7 +3397,7 @@ mod tests {
     fn test_rposition_fail() {
         let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
         let mut i = 0;
-        do rposition(v) |_elt| {
+        do v.rposition |_elt| {
             if i == 2 {
                 fail!()
             }
diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs
index d21888f12ec..eeff4b71c0d 100644
--- a/src/test/bench/graph500-bfs.rs
+++ b/src/test/bench/graph500-bfs.rs
@@ -341,7 +341,7 @@ fn validate(edges: ~[(node_id, node_id)],
         }
         else {
             while parent != root {
-                if vec::contains(path, &parent) {
+                if path.contains(&parent) {
                     status = false;
                 }