From 7d3b0bf3912fabf52fdd6926900e578e55af1b49 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 17 Apr 2014 15:28:14 -0700 Subject: std: Make ~[T] no longer a growable vector This removes all resizability support for ~[T] vectors in preparation of DST. The only growable vector remaining is Vec. In summary, the following methods from ~[T] and various functions were removed. Each method/function has an equivalent on the Vec type in std::vec unless otherwise stated. * slice::OwnedCloneableVector * slice::OwnedEqVector * slice::append * slice::append_one * slice::build (no replacement) * slice::bytes::push_bytes * slice::from_elem * slice::from_fn * slice::with_capacity * ~[T].capacity() * ~[T].clear() * ~[T].dedup() * ~[T].extend() * ~[T].grow() * ~[T].grow_fn() * ~[T].grow_set() * ~[T].insert() * ~[T].pop() * ~[T].push() * ~[T].push_all() * ~[T].push_all_move() * ~[T].remove() * ~[T].reserve() * ~[T].reserve_additional() * ~[T].reserve_exect() * ~[T].retain() * ~[T].set_len() * ~[T].shift() * ~[T].shrink_to_fit() * ~[T].swap_remove() * ~[T].truncate() * ~[T].unshift() * ~str.clear() * ~str.set_len() * ~str.truncate() Note that no other API changes were made. Existing apis that took or returned ~[T] continue to do so. [breaking-change] --- src/libstd/num/int_macros.rs | 4 ++-- src/libstd/num/mod.rs | 3 +-- src/libstd/num/strconv.rs | 42 ++++++++++++++++++++++-------------------- src/libstd/num/uint_macros.rs | 4 ++-- 4 files changed, 27 insertions(+), 26 deletions(-) (limited to 'src/libstd/num') 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 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 ~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()) } } } -- cgit 1.4.1-3-g733a5