diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 25aeccdcbed..338fd86ad1e 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -520,10 +520,12 @@ impl ToStrRadix for BigUint { fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str { if v.is_empty() { return ~"0" } - let s = vec::reversed(v).map(|n| { - let s = uint::to_str_radix(*n as uint, radix); - str::from_chars(vec::from_elem(l - s.len(), '0')) + s - }).concat(); + let mut s = str::with_capacity(v.len() * l); + for v.rev_iter().advance |n| { + let ss = uint::to_str_radix(*n as uint, radix); + s.push_str("0".repeat(l - ss.len())); + s.push_str(ss); + } s.trim_left_chars(&'0').to_owned() } } @@ -1629,7 +1631,6 @@ mod bigint_tests { use std::int; use std::num::{IntConvertible, Zero, One, FromStrRadix}; use std::uint; - use std::vec; #[test] fn test_from_biguint() { @@ -1646,9 +1647,11 @@ mod bigint_tests { #[test] fn test_cmp() { - let vs = [ &[2], &[1, 1], &[2, 1], &[1, 1, 1] ]; - let mut nums = vec::reversed(vs) - .map(|s| BigInt::from_slice(Minus, *s)); + let vs = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ]; + let mut nums = ~[]; + for vs.rev_iter().advance |s| { + nums.push(BigInt::from_slice(Minus, *s)); + } nums.push(Zero::zero()); nums.push_all_move(vs.map(|s| BigInt::from_slice(Plus, *s))); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 6847e298a2c..ebd11e2f668 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -41,7 +41,6 @@ use syntax::opt_vec::OptVec; use std::str; use std::uint; -use std::vec; use std::hashmap::{HashMap, HashSet}; use std::util; @@ -5360,7 +5359,7 @@ impl Resolver { if idents.len() == 0 { return ~"???"; } - return self.idents_to_str(vec::reversed(idents)); + return self.idents_to_str(idents.consume_rev_iter().collect::<~[ast::ident]>()); } pub fn dump_module(@mut self, module_: @mut Module) { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 5d4943c49d9..b6d99d920e2 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -436,16 +436,6 @@ pub fn zip(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] { w } -/// Returns a vector with the order of elements reversed -pub fn reversed(v: &[T]) -> ~[T] { - let mut rs: ~[T] = ~[]; - let mut i = v.len(); - if i == 0 { return (rs); } else { i -= 1; } - while i != 0 { rs.push(copy v[i]); i -= 1; } - rs.push(copy v[0]); - rs -} - /** * Iterate over all permutations of vector `v`. * @@ -2628,31 +2618,17 @@ mod tests { } #[test] - fn reverse_and_reversed() { + fn test_reverse() { let mut v: ~[int] = ~[10, 20]; assert_eq!(v[0], 10); assert_eq!(v[1], 20); v.reverse(); assert_eq!(v[0], 20); assert_eq!(v[1], 10); - let v2 = reversed::([10, 20]); - assert_eq!(v2[0], 20); - assert_eq!(v2[1], 10); - v[0] = 30; - assert_eq!(v2[0], 20); - // Make sure they work with 0-length vectors too. - let v4 = reversed::([]); - assert_eq!(v4, ~[]); let mut v3: ~[int] = ~[]; v3.reverse(); - } - - #[test] - fn reversed_mut() { - let v2 = reversed::([10, 20]); - assert_eq!(v2[0], 20); - assert_eq!(v2[1], 10); + assert!(v3.is_empty()); } #[test] diff --git a/src/test/run-pass/import-glob-crate.rs b/src/test/run-pass/import-glob-crate.rs index b036a57e19c..d09ef3bc25c 100644 --- a/src/test/run-pass/import-glob-crate.rs +++ b/src/test/run-pass/import-glob-crate.rs @@ -17,5 +17,5 @@ use std::vec::*; pub fn main() { let mut v = from_elem(0u, 0); v = append(v, ~[4, 2]); - assert_eq!(reversed(v), ~[2, 4]); + assert_eq!(from_fn(2, |i| 2*(i+1)), ~[2, 4]); }