about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-29 18:56:36 -0700
committerbors <bors@rust-lang.org>2014-03-29 18:56:36 -0700
commitd79fbba0db84b2d27440f8feba715dffd3aeaa01 (patch)
treed5f8701b97fcf2fc596a52215ad96462c1eb981e /src/libstd
parent86890b9e7c5db28ac2da5cd63d1a51d63a5e6bec (diff)
parentc356e3ba6a12c3294a9a428ef9120cff9306bf4b (diff)
downloadrust-d79fbba0db84b2d27440f8feba715dffd3aeaa01.tar.gz
rust-d79fbba0db84b2d27440f8feba715dffd3aeaa01.zip
auto merge of #13203 : Kimundi/rust/de-map-vec3, r=cmr
They required unnecessary temporaries, are replaced with iterators, and would conflict with a possible future `Iterable` trait.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ascii.rs4
-rw-r--r--src/libstd/io/net/addrinfo.rs5
-rw-r--r--src/libstd/slice.rs81
-rw-r--r--src/libstd/vec.rs7
4 files changed, 6 insertions, 91 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs
index 85df875dc1d..57f7d183458 100644
--- a/src/libstd/ascii.rs
+++ b/src/libstd/ascii.rs
@@ -285,12 +285,12 @@ impl<'a> AsciiStr for &'a [Ascii] {
 
     #[inline]
     fn to_lower(&self) -> ~[Ascii] {
-        self.map(|a| a.to_lower())
+        self.iter().map(|a| a.to_lower()).collect()
     }
 
     #[inline]
     fn to_upper(&self) -> ~[Ascii] {
-        self.map(|a| a.to_upper())
+        self.iter().map(|a| a.to_upper()).collect()
     }
 
     #[inline]
diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs
index f16db6e76c9..bf573bfaed8 100644
--- a/src/libstd/io/net/addrinfo.rs
+++ b/src/libstd/io/net/addrinfo.rs
@@ -19,11 +19,12 @@ getaddrinfo()
 
 #![allow(missing_doc)]
 
+use iter::Iterator;
 use io::IoResult;
 use io::net::ip::{SocketAddr, IpAddr};
 use option::{Option, Some, None};
 use rt::rtio::{IoFactory, LocalIo};
-use slice::ImmutableVector;
+use slice::OwnedVector;
 
 /// Hints to the types of sockets that are desired when looking up hosts
 pub enum SocketType {
@@ -73,7 +74,7 @@ pub struct Info {
 /// Easy name resolution. Given a hostname, returns the list of IP addresses for
 /// that hostname.
 pub fn get_host_addresses(host: &str) -> IoResult<~[IpAddr]> {
-    lookup(Some(host), None, None).map(|a| a.map(|i| i.address.ip))
+    lookup(Some(host), None, None).map(|a| a.move_iter().map(|i| i.address.ip).collect())
 }
 
 /// Full-fleged resolution. This function will perform a synchronous call to
diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs
index b5055dfe8b3..4a720aefa4e 100644
--- a/src/libstd/slice.rs
+++ b/src/libstd/slice.rs
@@ -348,16 +348,6 @@ pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
 
 // Functional utilities
 
-/**
- * Apply a function to each element of a vector and return a concatenation
- * of each result vector
- */
-pub fn flat_map<T, U>(v: &[T], f: |t: &T| -> ~[U]) -> ~[U] {
-    let mut result = ~[];
-    for elem in v.iter() { result.push_all_move(f(elem)); }
-    result
-}
-
 #[allow(missing_doc)]
 pub trait VectorVector<T> {
     // FIXME #5898: calling these .concat and .connect conflicts with
@@ -902,11 +892,7 @@ pub trait ImmutableVector<'a, T> {
     fn initn(&self, n: uint) -> &'a [T];
     /// Returns the last element of a vector, or `None` if it is empty.
     fn last(&self) -> Option<&'a T>;
-    /**
-     * Apply a function to each element of a vector and return a concatenation
-     * of each result vector
-     */
-    fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U];
+
     /// Returns a pointer to the element at the given index, without doing
     /// bounds checking.
     unsafe fn unsafe_ref(self, index: uint) -> &'a T;
@@ -935,11 +921,6 @@ pub trait ImmutableVector<'a, T> {
      */
     fn bsearch(&self, f: |&T| -> Ordering) -> Option<uint>;
 
-    /// Deprecated, use iterators where possible
-    /// (`self.iter().map(f)`). Apply a function to each element
-    /// of a vector and return the results.
-    fn map<U>(&self, |t: &T| -> U) -> ~[U];
-
     /**
      * Returns a mutable reference to the first element in this slice
      * and adjusts the slice in place so that it no longer contains
@@ -1095,11 +1076,6 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
     }
 
     #[inline]
-    fn flat_map<U>(&self, f: |t: &T| -> ~[U]) -> ~[U] {
-        flat_map(*self, f)
-    }
-
-    #[inline]
     unsafe fn unsafe_ref(self, index: uint) -> &'a T {
         transmute(self.repr().data.offset(index as int))
     }
@@ -1129,10 +1105,6 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
         return None;
     }
 
-    fn map<U>(&self, f: |t: &T| -> U) -> ~[U] {
-        self.iter().map(f).collect()
-    }
-
     fn shift_ref(&mut self) -> Option<&'a T> {
         if self.len() == 0 { return None; }
         unsafe {
@@ -3330,27 +3302,6 @@ mod tests {
     }
 
     #[test]
-    fn test_map() {
-        // Test on-stack map.
-        let v = &[1u, 2u, 3u];
-        let mut w = v.map(square_ref);
-        assert_eq!(w.len(), 3u);
-        assert_eq!(w[0], 1u);
-        assert_eq!(w[1], 4u);
-        assert_eq!(w[2], 9u);
-
-        // Test on-heap map.
-        let v = ~[1u, 2u, 3u, 4u, 5u];
-        w = v.map(square_ref);
-        assert_eq!(w.len(), 5u);
-        assert_eq!(w[0], 1u);
-        assert_eq!(w[1], 4u);
-        assert_eq!(w[2], 9u);
-        assert_eq!(w[3], 16u);
-        assert_eq!(w[4], 25u);
-    }
-
-    #[test]
     fn test_retain() {
         let mut v = ~[1, 2, 3, 4, 5];
         v.retain(is_odd);
@@ -3732,36 +3683,6 @@ mod tests {
 
     #[test]
     #[should_fail]
-    fn test_map_fail() {
-        use rc::Rc;
-        let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
-        let mut i = 0;
-        v.map(|_elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 1;
-            ~[(~0, Rc::new(0))]
-        });
-    }
-
-    #[test]
-    #[should_fail]
-    fn test_flat_map_fail() {
-        use rc::Rc;
-        let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
-        let mut i = 0;
-        flat_map(v, |_elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 1;
-            ~[(~0, Rc::new(0))]
-        });
-    }
-
-    #[test]
-    #[should_fail]
     fn test_permute_fail() {
         use rc::Rc;
         let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 4454801c129..11fd2b8ee22 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -902,13 +902,6 @@ impl<T> Vec<T> {
         }
     }
 
-    ///Apply a function to each element of a vector and return the results.
-    #[inline]
-    #[deprecated="Use `xs.iter().map(closure)` instead."]
-    pub fn map<U>(&self, f: |t: &T| -> U) -> Vec<U> {
-        self.iter().map(f).collect()
-    }
-
     /// Takes ownership of the vector `other`, moving all elements into
     /// the current vector. This does not copy any elements, and it is
     /// illegal to use the `other` vector after calling this method