diff options
Diffstat (limited to 'src/libstd/num')
| -rw-r--r-- | src/libstd/num/int_macros.rs | 4 | ||||
| -rw-r--r-- | src/libstd/num/mod.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/strconv.rs | 42 | ||||
| -rw-r--r-- | src/libstd/num/uint_macros.rs | 4 | 
4 files changed, 27 insertions, 26 deletions
diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 1d2c38f22bb..3228b5a1a49 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -277,13 +277,13 @@ impl ToStrRadix for $T { /// Convert to a string in a given base. #[inline] fn to_str_radix(&self, radix: uint) -> ~str { - let mut buf: ~[u8] = ~[]; + let mut buf = Vec::new(); strconv::int_to_str_bytes_common(*self, radix, strconv::SignNeg, |i| { buf.push(i); }); // We know we generated valid utf-8, so we don't need to go through that // check. - unsafe { str::raw::from_utf8_owned(buf) } + unsafe { str::raw::from_utf8_owned(buf.move_iter().collect()) } } } diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 7ddefe9a63d..12befed743a 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -1779,12 +1779,11 @@ mod bench { extern crate test; use self::test::Bencher; use num; - use slice; use prelude::*; #[bench] fn bench_pow_function(b: &mut Bencher) { - let v = slice::from_fn(1024, |n| n); + let v = Vec::from_fn(1024, |n| n); b.iter(|| {v.iter().fold(0, |old, new| num::pow(old, *new));}); } } diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 3ce9a3d0764..ffcb129d635 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -10,19 +10,21 @@ #![allow(missing_doc)] +use char; use clone::Clone; use container::Container; -use std::cmp::{Ord, Eq}; +use iter::Iterator; +use num::{NumCast, Zero, One, cast, Int}; +use num::{Round, Float, FPNaN, FPInfinite, ToPrimitive}; +use num; use ops::{Add, Sub, Mul, Div, Rem, Neg}; use option::{None, Option, Some}; -use char; +use slice::OwnedVector; +use slice::{CloneableVector, ImmutableVector, MutableVector}; +use std::cmp::{Ord, Eq}; use str::{StrSlice}; use str; -use slice::{CloneableVector, ImmutableVector, MutableVector}; -use slice::OwnedVector; -use num; -use num::{NumCast, Zero, One, cast, Int}; -use num::{Round, Float, FPNaN, FPInfinite, ToPrimitive}; +use vec::Vec; /// A flag that specifies whether to use exponential (scientific) notation. pub enum ExponentFormat { @@ -293,7 +295,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+ } let neg = num < _0 || (negative_zero && _1 / num == Float::neg_infinity()); - let mut buf: ~[u8] = ~[]; + let mut buf = Vec::new(); let radix_gen: T = cast(radix as int).unwrap(); let (num, exp) = match exp_format { @@ -411,23 +413,23 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+ // If reached left end of number, have to // insert additional digit: if i < 0 - || buf[i as uint] == '-' as u8 - || buf[i as uint] == '+' as u8 { + || *buf.get(i as uint) == '-' as u8 + || *buf.get(i as uint) == '+' as u8 { buf.insert((i + 1) as uint, value2ascii(1)); break; } // Skip the '.' - if buf[i as uint] == '.' as u8 { i -= 1; continue; } + if *buf.get(i as uint) == '.' as u8 { i -= 1; continue; } // Either increment the digit, // or set to 0 if max and carry the 1. - let current_digit = ascii2value(buf[i as uint]); + let current_digit = ascii2value(*buf.get(i as uint)); if current_digit < (radix - 1) { - buf[i as uint] = value2ascii(current_digit+1); + *buf.get_mut(i as uint) = value2ascii(current_digit+1); break; } else { - buf[i as uint] = value2ascii(0); + *buf.get_mut(i as uint) = value2ascii(0); i -= 1; } } @@ -444,25 +446,25 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+ let mut i = buf_max_i; // discover trailing zeros of fractional part - while i > start_fractional_digits && buf[i] == '0' as u8 { + while i > start_fractional_digits && *buf.get(i) == '0' as u8 { i -= 1; } // Only attempt to truncate digits if buf has fractional digits if i >= start_fractional_digits { // If buf ends with '.', cut that too. - if buf[i] == '.' as u8 { i -= 1 } + if *buf.get(i) == '.' as u8 { i -= 1 } // only resize buf if we actually remove digits if i < buf_max_i { - buf = buf.slice(0, i + 1).to_owned(); + buf = Vec::from_slice(buf.slice(0, i + 1)); } } } // If exact and trailing '.', just cut that else { let max_i = buf.len() - 1; - if buf[max_i] == '.' as u8 { - buf = buf.slice(0, max_i).to_owned(); + if *buf.get(max_i) == '.' as u8 { + buf = Vec::from_slice(buf.slice(0, max_i)); } } @@ -481,7 +483,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+ } } - (buf, false) + (buf.move_iter().collect(), false) } /** diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index ece30e72e06..61723f339ae 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -191,13 +191,13 @@ impl ToStrRadix for $T { /// Convert to a string in a given base. #[inline] fn to_str_radix(&self, radix: uint) -> ~str { - let mut buf = ~[]; + let mut buf = Vec::new(); strconv::int_to_str_bytes_common(*self, radix, strconv::SignNone, |i| { buf.push(i); }); // We know we generated valid utf-8, so we don't need to go through that // check. - unsafe { str::raw::from_utf8_owned(buf) } + unsafe { str::raw::from_utf8_owned(buf.move_iter().collect()) } } }  | 
