From a65411e4f7b5df78e34dcaf8061d4641f4b56412 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 9 Apr 2014 11:43:33 +1000 Subject: std,serialize: remove some internal uses of ~[]. These are all private uses of ~[], so can easily & non-controversially be replaced with Vec. --- src/libstd/sync/deque.rs | 16 ++++++++-------- src/libstd/sync/mpmc_bounded_queue.rs | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index d01c89878de..8beadce2160 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -62,6 +62,7 @@ use sync::arc::UnsafeArc; use sync::atomics::{AtomicInt, AtomicPtr, SeqCst}; use unstable::sync::Exclusive; use slice::{OwnedVector, ImmutableVector}; +use vec::Vec; // Once the queue is less than 1/K full, then it will be downsized. Note that // the deque requires that this number be less than 2. @@ -116,14 +117,14 @@ pub enum Stolen { /// will only use this structure when allocating a new buffer or deallocating a /// previous one. pub struct BufferPool { - pool: Exclusive<~[~Buffer]>, + pool: Exclusive>>, } /// An internal buffer used by the chase-lev deque. This structure is actually /// implemented as a circular buffer, and is used as the intermediate storage of /// the data in the deque. /// -/// This type is implemented with *T instead of ~[T] for two reasons: +/// This type is implemented with *T instead of Vec for two reasons: /// /// 1. There is nothing safe about using this buffer. This easily allows the /// same value to be read twice in to rust, and there is nothing to @@ -132,7 +133,7 @@ pub struct BufferPool { /// destructors for values in this buffer (on drop) because the bounds /// are defined by the deque it's owned by. /// -/// 2. We can certainly avoid bounds checks using *T instead of ~[T], although +/// 2. We can certainly avoid bounds checks using *T instead of Vec, although /// LLVM is probably pretty good at doing this already. struct Buffer { storage: *T, @@ -143,7 +144,7 @@ impl BufferPool { /// Allocates a new buffer pool which in turn can be used to allocate new /// deques. pub fn new() -> BufferPool { - BufferPool { pool: Exclusive::new(~[]) } + BufferPool { pool: Exclusive::new(vec!()) } } /// Allocates a new work-stealing deque which will send/receiving memory to @@ -494,7 +495,7 @@ mod tests { } } }) - }).collect::<~[Thread<()>]>(); + }).collect::>>(); while remaining.load(SeqCst) > 0 { match w.pop() { @@ -525,7 +526,7 @@ mod tests { Thread::start(proc() { stampede(w, s, 4, 10000); }) - }).collect::<~[Thread<()>]>(); + }).collect::>>(); for thread in threads.move_iter() { thread.join(); @@ -556,7 +557,7 @@ mod tests { } } }) - }).collect::<~[Thread<()>]>(); + }).collect::>>(); let mut rng = rand::task_rng(); let mut expected = 0; @@ -658,4 +659,3 @@ mod tests { } } } - diff --git a/src/libstd/sync/mpmc_bounded_queue.rs b/src/libstd/sync/mpmc_bounded_queue.rs index 12c05c0d61c..b392cc8ff9a 100644 --- a/src/libstd/sync/mpmc_bounded_queue.rs +++ b/src/libstd/sync/mpmc_bounded_queue.rs @@ -35,7 +35,7 @@ use num::next_power_of_two; use option::{Option, Some, None}; use sync::arc::UnsafeArc; use sync::atomics::{AtomicUint,Relaxed,Release,Acquire}; -use slice; +use vec::Vec; struct Node { sequence: AtomicUint, @@ -44,7 +44,7 @@ struct Node { struct State { pad0: [u8, ..64], - buffer: ~[Node], + buffer: Vec>, mask: uint, pad1: [u8, ..64], enqueue_pos: AtomicUint, @@ -69,7 +69,7 @@ impl State { } else { capacity }; - let buffer = slice::from_fn(capacity, |i| { + let buffer = Vec::from_fn(capacity, |i| { Node { sequence:AtomicUint::new(i), value: None } }); State{ @@ -88,7 +88,7 @@ impl State { let mask = self.mask; let mut pos = self.enqueue_pos.load(Relaxed); loop { - let node = &mut self.buffer[pos & mask]; + let node = self.buffer.get_mut(pos & mask); let seq = node.sequence.load(Acquire); let diff: int = seq as int - pos as int; @@ -114,7 +114,7 @@ impl State { let mask = self.mask; let mut pos = self.dequeue_pos.load(Relaxed); loop { - let node = &mut self.buffer[pos & mask]; + let node = self.buffer.get_mut(pos & mask); let seq = node.sequence.load(Acquire); let diff: int = seq as int - (pos + 1) as int; if diff == 0 { @@ -186,7 +186,7 @@ mod tests { }); } - let mut completion_rxs = ~[]; + let mut completion_rxs = vec![]; for _ in range(0, nthreads) { let (tx, rx) = channel(); completion_rxs.push(rx); -- cgit 1.4.1-3-g733a5