Skip to content

Commit 7d3b0bf

Browse files
committed
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<T>. 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]
1 parent ce2bab6 commit 7d3b0bf

28 files changed

+342
-999
lines changed

src/libstd/comm/shared.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rt::task::{Task, BlockedTask};
3030
use rt::thread::Thread;
3131
use sync::atomics;
3232
use unstable::mutex::NativeMutex;
33-
use slice::OwnedVector;
3433

3534
use mpsc = sync::mpsc_queue;
3635

src/libstd/comm/stream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rt::task::{Task, BlockedTask};
3030
use rt::thread::Thread;
3131
use spsc = sync::spsc_queue;
3232
use sync::atomics;
33-
use slice::OwnedVector;
3433

3534
static DISCONNECTED: int = int::MIN;
3635
#[cfg(test)]

src/libstd/hash/sip.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,8 @@ pub fn hash_with_keys<T: Hash<SipState>>(k0: u64, k1: u64, value: &T) -> u64 {
359359
#[cfg(test)]
360360
mod tests {
361361
extern crate test;
362-
use io::Writer;
363-
use iter::Iterator;
362+
use prelude::*;
364363
use num::ToStrRadix;
365-
use option::{Some, None};
366-
use str::Str;
367-
use strbuf::StrBuf;
368-
use slice::{Vector, ImmutableVector, OwnedVector};
369364
use self::test::Bencher;
370365

371366
use super::super::Hash;
@@ -454,7 +449,7 @@ mod tests {
454449

455450
let k0 = 0x_07_06_05_04_03_02_01_00_u64;
456451
let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64;
457-
let mut buf : ~[u8] = ~[];
452+
let mut buf = Vec::new();
458453
let mut t = 0;
459454
let mut state_inc = SipState::new_with_keys(k0, k1);
460455
let mut state_full = SipState::new_with_keys(k0, k1);
@@ -496,7 +491,7 @@ mod tests {
496491
assert_eq!(vec, out);
497492

498493
state_full.reset();
499-
state_full.write(buf);
494+
state_full.write(buf.as_slice());
500495
let f = result_str(state_full.result());
501496
let i = result_str(state_inc.result());
502497
let v = to_hex_str(&vecs[t]);

src/libstd/io/buffered.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use iter::ExactSize;
1717
use ops::Drop;
1818
use option::{Some, None, Option};
1919
use result::{Ok, Err};
20-
use slice::{OwnedVector, ImmutableVector, MutableVector};
20+
use slice::{ImmutableVector, MutableVector};
2121
use slice;
2222
use vec::Vec;
2323

@@ -391,7 +391,7 @@ mod test {
391391

392392
/// A dummy reader intended at testing short-reads propagation.
393393
pub struct ShortReader {
394-
lengths: ~[uint],
394+
lengths: Vec<uint>,
395395
}
396396

397397
impl Reader for ShortReader {
@@ -554,7 +554,7 @@ mod test {
554554

555555
#[test]
556556
fn test_short_reads() {
557-
let inner = ShortReader{lengths: ~[0, 1, 2, 0, 1, 0]};
557+
let inner = ShortReader{lengths: vec![0, 1, 2, 0, 1, 0]};
558558
let mut reader = BufferedReader::new(inner);
559559
let mut buf = [0, 0];
560560
assert_eq!(reader.read(buf), Ok(0));

src/libstd/io/extensions.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use option::{Option, Some, None};
2121
use result::{Ok, Err};
2222
use io;
2323
use io::{IoError, IoResult, Reader};
24-
use slice::{OwnedVector, ImmutableVector, Vector};
24+
use slice::{ImmutableVector, Vector};
2525
use ptr::RawPtr;
2626

2727
/// An iterator that reads a single byte on each iteration,
@@ -503,21 +503,22 @@ mod test {
503503
#[cfg(test)]
504504
mod bench {
505505
extern crate test;
506-
use self::test::Bencher;
506+
507507
use container::Container;
508+
use prelude::*;
509+
use self::test::Bencher;
508510

509511
macro_rules! u64_from_be_bytes_bench_impl(
510512
($size:expr, $stride:expr, $start_index:expr) =>
511513
({
512-
use slice;
513514
use super::u64_from_be_bytes;
514515

515-
let data = slice::from_fn($stride*100+$start_index, |i| i as u8);
516+
let data = Vec::from_fn($stride*100+$start_index, |i| i as u8);
516517
let mut sum = 0u64;
517518
b.iter(|| {
518519
let mut i = $start_index;
519520
while i < data.len() {
520-
sum += u64_from_be_bytes(data, i, $size);
521+
sum += u64_from_be_bytes(data.as_slice(), i, $size);
521522
i += $stride;
522523
}
523524
});

src/libstd/io/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use result::{Err, Ok};
1717
use io;
1818
use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult};
1919
use slice;
20-
use slice::{Vector, ImmutableVector, MutableVector, OwnedCloneableVector};
20+
use slice::{Vector, ImmutableVector, MutableVector};
2121
use vec::Vec;
2222

2323
fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64> {

src/libstd/io/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ use os;
228228
use option::{Option, Some, None};
229229
use path::Path;
230230
use result::{Ok, Err, Result};
231-
use str::{StrSlice, OwnedStr};
231+
use str::StrSlice;
232232
use str;
233233
use uint;
234234
use unstable::finally::try_finally;
235-
use slice::{Vector, OwnedVector, MutableVector, ImmutableVector, OwnedCloneableVector};
235+
use slice::{Vector, MutableVector, ImmutableVector};
236236
use vec::Vec;
237237

238238
// Reexports

src/libstd/io/process.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use fmt;
1616
use io::IoResult;
1717
use io;
1818
use libc;
19+
use mem;
1920
use rt::rtio::{RtioProcess, IoFactory, LocalIo};
2021

2122
/// Signal a process to exit, without forcibly killing it. Corresponds to
@@ -416,12 +417,7 @@ impl Drop for Process {
416417
drop(self.stdin.take());
417418
drop(self.stdout.take());
418419
drop(self.stderr.take());
419-
loop {
420-
match self.extra_io.pop() {
421-
Some(_) => (),
422-
None => break,
423-
}
424-
}
420+
drop(mem::replace(&mut self.extra_io, ~[]));
425421

426422
self.wait();
427423
}

src/libstd/io/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use mem::drop;
2828
use option::{Some, None};
2929
use result::{Ok, Err};
3030
use rt::rtio::{IoFactory, LocalIo, RtioSignal};
31-
use slice::{ImmutableVector, OwnedVector};
31+
use slice::ImmutableVector;
3232
use vec::Vec;
3333

3434
/// Signals that can be sent and received

src/libstd/local_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use kinds::Send;
4646
use mem::replace;
4747
use option::{None, Option, Some};
4848
use rt::task::{Task, LocalStorage};
49-
use slice::{ImmutableVector, MutableVector, OwnedVector};
49+
use slice::{ImmutableVector, MutableVector};
5050
use vec::Vec;
5151

5252
/**

src/libstd/num/int_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ impl ToStrRadix for $T {
277277
/// Convert to a string in a given base.
278278
#[inline]
279279
fn to_str_radix(&self, radix: uint) -> ~str {
280-
let mut buf: ~[u8] = ~[];
280+
let mut buf = Vec::new();
281281
strconv::int_to_str_bytes_common(*self, radix, strconv::SignNeg, |i| {
282282
buf.push(i);
283283
});
284284
// We know we generated valid utf-8, so we don't need to go through that
285285
// check.
286-
unsafe { str::raw::from_utf8_owned(buf) }
286+
unsafe { str::raw::from_utf8_owned(buf.move_iter().collect()) }
287287
}
288288
}
289289

src/libstd/num/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,12 +1779,11 @@ mod bench {
17791779
extern crate test;
17801780
use self::test::Bencher;
17811781
use num;
1782-
use slice;
17831782
use prelude::*;
17841783

17851784
#[bench]
17861785
fn bench_pow_function(b: &mut Bencher) {
1787-
let v = slice::from_fn(1024, |n| n);
1786+
let v = Vec::from_fn(1024, |n| n);
17881787
b.iter(|| {v.iter().fold(0, |old, new| num::pow(old, *new));});
17891788
}
17901789
}

src/libstd/num/strconv.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010

1111
#![allow(missing_doc)]
1212

13+
use char;
1314
use clone::Clone;
1415
use container::Container;
15-
use std::cmp::{Ord, Eq};
16+
use iter::Iterator;
17+
use num::{NumCast, Zero, One, cast, Int};
18+
use num::{Round, Float, FPNaN, FPInfinite, ToPrimitive};
19+
use num;
1620
use ops::{Add, Sub, Mul, Div, Rem, Neg};
1721
use option::{None, Option, Some};
18-
use char;
22+
use slice::OwnedVector;
23+
use slice::{CloneableVector, ImmutableVector, MutableVector};
24+
use std::cmp::{Ord, Eq};
1925
use str::{StrSlice};
2026
use str;
21-
use slice::{CloneableVector, ImmutableVector, MutableVector};
22-
use slice::OwnedVector;
23-
use num;
24-
use num::{NumCast, Zero, One, cast, Int};
25-
use num::{Round, Float, FPNaN, FPInfinite, ToPrimitive};
27+
use vec::Vec;
2628

2729
/// A flag that specifies whether to use exponential (scientific) notation.
2830
pub enum ExponentFormat {
@@ -293,7 +295,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+
293295
}
294296

295297
let neg = num < _0 || (negative_zero && _1 / num == Float::neg_infinity());
296-
let mut buf: ~[u8] = ~[];
298+
let mut buf = Vec::new();
297299
let radix_gen: T = cast(radix as int).unwrap();
298300

299301
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+
411413
// If reached left end of number, have to
412414
// insert additional digit:
413415
if i < 0
414-
|| buf[i as uint] == '-' as u8
415-
|| buf[i as uint] == '+' as u8 {
416+
|| *buf.get(i as uint) == '-' as u8
417+
|| *buf.get(i as uint) == '+' as u8 {
416418
buf.insert((i + 1) as uint, value2ascii(1));
417419
break;
418420
}
419421

420422
// Skip the '.'
421-
if buf[i as uint] == '.' as u8 { i -= 1; continue; }
423+
if *buf.get(i as uint) == '.' as u8 { i -= 1; continue; }
422424

423425
// Either increment the digit,
424426
// or set to 0 if max and carry the 1.
425-
let current_digit = ascii2value(buf[i as uint]);
427+
let current_digit = ascii2value(*buf.get(i as uint));
426428
if current_digit < (radix - 1) {
427-
buf[i as uint] = value2ascii(current_digit+1);
429+
*buf.get_mut(i as uint) = value2ascii(current_digit+1);
428430
break;
429431
} else {
430-
buf[i as uint] = value2ascii(0);
432+
*buf.get_mut(i as uint) = value2ascii(0);
431433
i -= 1;
432434
}
433435
}
@@ -444,25 +446,25 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+
444446
let mut i = buf_max_i;
445447

446448
// discover trailing zeros of fractional part
447-
while i > start_fractional_digits && buf[i] == '0' as u8 {
449+
while i > start_fractional_digits && *buf.get(i) == '0' as u8 {
448450
i -= 1;
449451
}
450452

451453
// Only attempt to truncate digits if buf has fractional digits
452454
if i >= start_fractional_digits {
453455
// If buf ends with '.', cut that too.
454-
if buf[i] == '.' as u8 { i -= 1 }
456+
if *buf.get(i) == '.' as u8 { i -= 1 }
455457

456458
// only resize buf if we actually remove digits
457459
if i < buf_max_i {
458-
buf = buf.slice(0, i + 1).to_owned();
460+
buf = Vec::from_slice(buf.slice(0, i + 1));
459461
}
460462
}
461463
} // If exact and trailing '.', just cut that
462464
else {
463465
let max_i = buf.len() - 1;
464-
if buf[max_i] == '.' as u8 {
465-
buf = buf.slice(0, max_i).to_owned();
466+
if *buf.get(max_i) == '.' as u8 {
467+
buf = Vec::from_slice(buf.slice(0, max_i));
466468
}
467469
}
468470

@@ -481,7 +483,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+
481483
}
482484
}
483485

484-
(buf, false)
486+
(buf.move_iter().collect(), false)
485487
}
486488

487489
/**

src/libstd/num/uint_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ impl ToStrRadix for $T {
191191
/// Convert to a string in a given base.
192192
#[inline]
193193
fn to_str_radix(&self, radix: uint) -> ~str {
194-
let mut buf = ~[];
194+
let mut buf = Vec::new();
195195
strconv::int_to_str_bytes_common(*self, radix, strconv::SignNone, |i| {
196196
buf.push(i);
197197
});
198198
// We know we generated valid utf-8, so we don't need to go through that
199199
// check.
200-
unsafe { str::raw::from_utf8_owned(buf) }
200+
unsafe { str::raw::from_utf8_owned(buf.move_iter().collect()) }
201201
}
202202
}
203203

0 commit comments

Comments
 (0)