Skip to content

Commit a65411e

Browse files
huonwalexcrichton
authored andcommitted
std,serialize: remove some internal uses of ~[].
These are all private uses of ~[], so can easily & non-controversially be replaced with Vec.
1 parent 342e8b5 commit a65411e

File tree

8 files changed

+43
-40
lines changed

8 files changed

+43
-40
lines changed

src/libserialize/ebml.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ pub mod writer {
636636
// ebml writing
637637
pub struct Encoder<'a, W> {
638638
pub writer: &'a mut W,
639-
size_positions: ~[uint],
639+
size_positions: Vec<uint>,
640640
}
641641

642642
fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
@@ -668,10 +668,9 @@ pub mod writer {
668668
}
669669

670670
pub fn Encoder<'a, W: Writer + Seek>(w: &'a mut W) -> Encoder<'a, W> {
671-
let size_positions: ~[uint] = ~[];
672671
Encoder {
673672
writer: w,
674-
size_positions: size_positions,
673+
size_positions: vec!(),
675674
}
676675
}
677676

src/libstd/io/extensions.rs

Lines changed: 5 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};
24+
use slice::{OwnedVector, ImmutableVector, Vector};
2525
use ptr::RawPtr;
2626

2727
/// An iterator that reads a single byte on each iteration,
@@ -88,15 +88,15 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
8888
8u => f(unsafe { transmute::<i64, [u8, ..8]>(to_le64(n as i64)) }),
8989
_ => {
9090

91-
let mut bytes: ~[u8] = ~[];
91+
let mut bytes = vec!();
9292
let mut i = size;
9393
let mut n = n;
9494
while i > 0u {
9595
bytes.push((n & 255_u64) as u8);
9696
n >>= 8_u64;
9797
i -= 1u;
9898
}
99-
f(bytes)
99+
f(bytes.as_slice())
100100
}
101101
}
102102
}
@@ -127,14 +127,14 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
127127
4u => f(unsafe { transmute::<i32, [u8, ..4]>(to_be32(n as i32)) }),
128128
8u => f(unsafe { transmute::<i64, [u8, ..8]>(to_be64(n as i64)) }),
129129
_ => {
130-
let mut bytes: ~[u8] = ~[];
130+
let mut bytes = vec!();
131131
let mut i = size;
132132
while i > 0u {
133133
let shift = ((i - 1u) * 8u) as u64;
134134
bytes.push((n >> shift) as u8);
135135
i -= 1u;
136136
}
137-
f(bytes)
137+
f(bytes.as_slice())
138138
}
139139
}
140140
}

src/libstd/io/signal.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use option::{Some, None};
2929
use result::{Ok, Err};
3030
use rt::rtio::{IoFactory, LocalIo, RtioSignal};
3131
use slice::{ImmutableVector, OwnedVector};
32+
use vec::Vec;
3233

3334
/// Signals that can be sent and received
3435
#[repr(int)]
@@ -80,7 +81,7 @@ pub enum Signum {
8081
/// ```
8182
pub struct Listener {
8283
/// A map from signums to handles to keep the handles in memory
83-
handles: ~[(Signum, ~RtioSignal:Send)],
84+
handles: Vec<(Signum, ~RtioSignal:Send)>,
8485
/// This is where all the handles send signums, which are received by
8586
/// the clients from the receiver.
8687
tx: Sender<Signum>,
@@ -99,7 +100,7 @@ impl Listener {
99100
Listener {
100101
tx: tx,
101102
rx: rx,
102-
handles: ~[],
103+
handles: vec!(),
103104
}
104105
}
105106

src/libstd/local_data.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use mem::replace;
4747
use option::{None, Option, Some};
4848
use rt::task::{Task, LocalStorage};
4949
use slice::{ImmutableVector, MutableVector, OwnedVector};
50+
use vec::Vec;
5051

5152
/**
5253
* Indexes a task-local data slot. This pointer is used for comparison to
@@ -89,7 +90,7 @@ impl<T: 'static> LocalData for T {}
8990
// n.b. If TLS is used heavily in future, this could be made more efficient with
9091
// a proper map.
9192
#[doc(hidden)]
92-
pub type Map = ~[Option<(*u8, TLSValue, LoanState)>];
93+
pub type Map = Vec<Option<(*u8, TLSValue, LoanState)>>;
9394
type TLSValue = ~LocalData:Send;
9495

9596
// Gets the map from the runtime. Lazily initialises if not done so already.
@@ -106,7 +107,7 @@ unsafe fn get_local_map() -> &mut Map {
106107
// If this is the first time we've accessed TLS, perform similar
107108
// actions to the oldsched way of doing things.
108109
&LocalStorage(ref mut slot) => {
109-
*slot = Some(~[]);
110+
*slot = Some(vec!());
110111
match *slot {
111112
Some(ref mut map_ptr) => { return map_ptr }
112113
None => abort()
@@ -237,7 +238,7 @@ fn get_with<T:'static,
237238
Some(i) => {
238239
let ret;
239240
let mut return_loan = false;
240-
match map[i] {
241+
match *map.get_mut(i) {
241242
Some((_, ref data, ref mut loan)) => {
242243
match (state, *loan) {
243244
(_, NoLoan) => {
@@ -271,7 +272,7 @@ fn get_with<T:'static,
271272
// in turn relocated the vector. Hence we do another lookup here to
272273
// fixup the loans.
273274
if return_loan {
274-
match map[i] {
275+
match *map.get_mut(i) {
275276
Some((_, _, ref mut loan)) => { *loan = NoLoan; }
276277
None => abort()
277278
}
@@ -331,7 +332,7 @@ pub fn set<T: 'static>(key: Key<T>, data: T) {
331332
// we're not actually sending it to other schedulers or anything.
332333
let data: ~LocalData:Send = unsafe { cast::transmute(data) };
333334
match insertion_position(map, keyval) {
334-
Some(i) => { map[i] = Some((keyval, data, NoLoan)); }
335+
Some(i) => { *map.get_mut(i) = Some((keyval, data, NoLoan)); }
335336
None => { map.push(Some((keyval, data, NoLoan))); }
336337
}
337338
}

src/libstd/repr.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use to_str::ToStr;
3131
use slice::{Vector, OwnedVector};
3232
use intrinsics::{Disr, Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
3333
use raw;
34+
use vec::Vec;
3435

3536
macro_rules! try( ($me:expr, $e:expr) => (
3637
match $e {
@@ -102,8 +103,8 @@ enum VariantState {
102103

103104
pub struct ReprVisitor<'a> {
104105
ptr: *u8,
105-
ptr_stk: ~[*u8],
106-
var_stk: ~[VariantState],
106+
ptr_stk: Vec<*u8>,
107+
var_stk: Vec<VariantState>,
107108
writer: &'a mut io::Writer,
108109
last_err: Option<io::IoError>,
109110
}
@@ -112,8 +113,8 @@ pub fn ReprVisitor<'a>(ptr: *u8,
112113
writer: &'a mut io::Writer) -> ReprVisitor<'a> {
113114
ReprVisitor {
114115
ptr: ptr,
115-
ptr_stk: ~[],
116-
var_stk: ~[],
116+
ptr_stk: vec!(),
117+
var_stk: vec!(),
117118
writer: writer,
118119
last_err: None,
119120
}
@@ -154,8 +155,8 @@ impl<'a> ReprVisitor<'a> {
154155
// issues we have to recreate it here.
155156
let u = ReprVisitor {
156157
ptr: ptr,
157-
ptr_stk: ~[],
158-
var_stk: ~[],
158+
ptr_stk: vec!(),
159+
var_stk: vec!(),
159160
writer: ::cast::transmute_copy(&self.writer),
160161
last_err: None,
161162
};
@@ -505,7 +506,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
505506
_offset: uint,
506507
inner: *TyDesc)
507508
-> bool {
508-
match self.var_stk[self.var_stk.len() - 1] {
509+
match *self.var_stk.get(self.var_stk.len() - 1) {
509510
Matched => {
510511
if i != 0 {
511512
try!(self, self.writer.write(", ".as_bytes()));
@@ -523,7 +524,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
523524
_disr_val: Disr,
524525
n_fields: uint,
525526
_name: &str) -> bool {
526-
match self.var_stk[self.var_stk.len() - 1] {
527+
match *self.var_stk.get(self.var_stk.len() - 1) {
527528
Matched => {
528529
if n_fields > 0 {
529530
try!(self, self.writer.write([')' as u8]));

src/libstd/rt/at_exit_imp.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use option::{Some, None};
2020
use ptr::RawPtr;
2121
use unstable::sync::Exclusive;
2222
use slice::OwnedVector;
23+
use vec::Vec;
2324

24-
type Queue = Exclusive<~[proc():Send]>;
25+
type Queue = Exclusive<Vec<proc():Send>>;
2526

2627
// You'll note that these variables are *not* atomic, and this is done on
2728
// purpose. This module is designed to have init() called *once* in a
@@ -35,7 +36,7 @@ pub fn init() {
3536
unsafe {
3637
rtassert!(!RUNNING);
3738
rtassert!(QUEUE.is_null());
38-
let state: ~Queue = ~Exclusive::new(~[]);
39+
let state: ~Queue = ~Exclusive::new(vec!());
3940
QUEUE = cast::transmute(state);
4041
}
4142
}
@@ -61,7 +62,7 @@ pub fn run() {
6162
QUEUE = 0 as *mut Queue;
6263
let mut vec = None;
6364
state.with(|arr| {
64-
vec = Some(mem::replace(arr, ~[]));
65+
vec = Some(mem::replace(arr, vec!()));
6566
});
6667
vec.take_unwrap()
6768
};

src/libstd/sync/deque.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use sync::arc::UnsafeArc;
6262
use sync::atomics::{AtomicInt, AtomicPtr, SeqCst};
6363
use unstable::sync::Exclusive;
6464
use slice::{OwnedVector, ImmutableVector};
65+
use vec::Vec;
6566

6667
// Once the queue is less than 1/K full, then it will be downsized. Note that
6768
// the deque requires that this number be less than 2.
@@ -116,14 +117,14 @@ pub enum Stolen<T> {
116117
/// will only use this structure when allocating a new buffer or deallocating a
117118
/// previous one.
118119
pub struct BufferPool<T> {
119-
pool: Exclusive<~[~Buffer<T>]>,
120+
pool: Exclusive<Vec<~Buffer<T>>>,
120121
}
121122

122123
/// An internal buffer used by the chase-lev deque. This structure is actually
123124
/// implemented as a circular buffer, and is used as the intermediate storage of
124125
/// the data in the deque.
125126
///
126-
/// This type is implemented with *T instead of ~[T] for two reasons:
127+
/// This type is implemented with *T instead of Vec<T> for two reasons:
127128
///
128129
/// 1. There is nothing safe about using this buffer. This easily allows the
129130
/// same value to be read twice in to rust, and there is nothing to
@@ -132,7 +133,7 @@ pub struct BufferPool<T> {
132133
/// destructors for values in this buffer (on drop) because the bounds
133134
/// are defined by the deque it's owned by.
134135
///
135-
/// 2. We can certainly avoid bounds checks using *T instead of ~[T], although
136+
/// 2. We can certainly avoid bounds checks using *T instead of Vec<T>, although
136137
/// LLVM is probably pretty good at doing this already.
137138
struct Buffer<T> {
138139
storage: *T,
@@ -143,7 +144,7 @@ impl<T: Send> BufferPool<T> {
143144
/// Allocates a new buffer pool which in turn can be used to allocate new
144145
/// deques.
145146
pub fn new() -> BufferPool<T> {
146-
BufferPool { pool: Exclusive::new(~[]) }
147+
BufferPool { pool: Exclusive::new(vec!()) }
147148
}
148149

149150
/// Allocates a new work-stealing deque which will send/receiving memory to
@@ -494,7 +495,7 @@ mod tests {
494495
}
495496
}
496497
})
497-
}).collect::<~[Thread<()>]>();
498+
}).collect::<Vec<Thread<()>>>();
498499

499500
while remaining.load(SeqCst) > 0 {
500501
match w.pop() {
@@ -525,7 +526,7 @@ mod tests {
525526
Thread::start(proc() {
526527
stampede(w, s, 4, 10000);
527528
})
528-
}).collect::<~[Thread<()>]>();
529+
}).collect::<Vec<Thread<()>>>();
529530

530531
for thread in threads.move_iter() {
531532
thread.join();
@@ -556,7 +557,7 @@ mod tests {
556557
}
557558
}
558559
})
559-
}).collect::<~[Thread<()>]>();
560+
}).collect::<Vec<Thread<()>>>();
560561

561562
let mut rng = rand::task_rng();
562563
let mut expected = 0;
@@ -658,4 +659,3 @@ mod tests {
658659
}
659660
}
660661
}
661-

src/libstd/sync/mpmc_bounded_queue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use num::next_power_of_two;
3535
use option::{Option, Some, None};
3636
use sync::arc::UnsafeArc;
3737
use sync::atomics::{AtomicUint,Relaxed,Release,Acquire};
38-
use slice;
38+
use vec::Vec;
3939

4040
struct Node<T> {
4141
sequence: AtomicUint,
@@ -44,7 +44,7 @@ struct Node<T> {
4444

4545
struct State<T> {
4646
pad0: [u8, ..64],
47-
buffer: ~[Node<T>],
47+
buffer: Vec<Node<T>>,
4848
mask: uint,
4949
pad1: [u8, ..64],
5050
enqueue_pos: AtomicUint,
@@ -69,7 +69,7 @@ impl<T: Send> State<T> {
6969
} else {
7070
capacity
7171
};
72-
let buffer = slice::from_fn(capacity, |i| {
72+
let buffer = Vec::from_fn(capacity, |i| {
7373
Node { sequence:AtomicUint::new(i), value: None }
7474
});
7575
State{
@@ -88,7 +88,7 @@ impl<T: Send> State<T> {
8888
let mask = self.mask;
8989
let mut pos = self.enqueue_pos.load(Relaxed);
9090
loop {
91-
let node = &mut self.buffer[pos & mask];
91+
let node = self.buffer.get_mut(pos & mask);
9292
let seq = node.sequence.load(Acquire);
9393
let diff: int = seq as int - pos as int;
9494

@@ -114,7 +114,7 @@ impl<T: Send> State<T> {
114114
let mask = self.mask;
115115
let mut pos = self.dequeue_pos.load(Relaxed);
116116
loop {
117-
let node = &mut self.buffer[pos & mask];
117+
let node = self.buffer.get_mut(pos & mask);
118118
let seq = node.sequence.load(Acquire);
119119
let diff: int = seq as int - (pos + 1) as int;
120120
if diff == 0 {
@@ -186,7 +186,7 @@ mod tests {
186186
});
187187
}
188188

189-
let mut completion_rxs = ~[];
189+
let mut completion_rxs = vec![];
190190
for _ in range(0, nthreads) {
191191
let (tx, rx) = channel();
192192
completion_rxs.push(rx);

0 commit comments

Comments
 (0)