std,serialize: remove some internal uses of ~[].
These are all private uses of ~[], so can easily & non-controversially be replaced with Vec.
This commit is contained in:
parent
342e8b59be
commit
a65411e4f7
8 changed files with 43 additions and 40 deletions
|
|
@ -636,7 +636,7 @@ pub mod writer {
|
|||
// ebml writing
|
||||
pub struct Encoder<'a, W> {
|
||||
pub writer: &'a mut W,
|
||||
size_positions: ~[uint],
|
||||
size_positions: Vec<uint>,
|
||||
}
|
||||
|
||||
fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
|
||||
|
|
@ -668,10 +668,9 @@ pub mod writer {
|
|||
}
|
||||
|
||||
pub fn Encoder<'a, W: Writer + Seek>(w: &'a mut W) -> Encoder<'a, W> {
|
||||
let size_positions: ~[uint] = ~[];
|
||||
Encoder {
|
||||
writer: w,
|
||||
size_positions: size_positions,
|
||||
size_positions: vec!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use option::{Option, Some, None};
|
|||
use result::{Ok, Err};
|
||||
use io;
|
||||
use io::{IoError, IoResult, Reader};
|
||||
use slice::{OwnedVector, ImmutableVector};
|
||||
use slice::{OwnedVector, ImmutableVector, Vector};
|
||||
use ptr::RawPtr;
|
||||
|
||||
/// An iterator that reads a single byte on each iteration,
|
||||
|
|
@ -88,7 +88,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
|||
8u => f(unsafe { transmute::<i64, [u8, ..8]>(to_le64(n as i64)) }),
|
||||
_ => {
|
||||
|
||||
let mut bytes: ~[u8] = ~[];
|
||||
let mut bytes = vec!();
|
||||
let mut i = size;
|
||||
let mut n = n;
|
||||
while i > 0u {
|
||||
|
|
@ -96,7 +96,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
|||
n >>= 8_u64;
|
||||
i -= 1u;
|
||||
}
|
||||
f(bytes)
|
||||
f(bytes.as_slice())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,14 +127,14 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
|||
4u => f(unsafe { transmute::<i32, [u8, ..4]>(to_be32(n as i32)) }),
|
||||
8u => f(unsafe { transmute::<i64, [u8, ..8]>(to_be64(n as i64)) }),
|
||||
_ => {
|
||||
let mut bytes: ~[u8] = ~[];
|
||||
let mut bytes = vec!();
|
||||
let mut i = size;
|
||||
while i > 0u {
|
||||
let shift = ((i - 1u) * 8u) as u64;
|
||||
bytes.push((n >> shift) as u8);
|
||||
i -= 1u;
|
||||
}
|
||||
f(bytes)
|
||||
f(bytes.as_slice())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use option::{Some, None};
|
|||
use result::{Ok, Err};
|
||||
use rt::rtio::{IoFactory, LocalIo, RtioSignal};
|
||||
use slice::{ImmutableVector, OwnedVector};
|
||||
use vec::Vec;
|
||||
|
||||
/// Signals that can be sent and received
|
||||
#[repr(int)]
|
||||
|
|
@ -80,7 +81,7 @@ pub enum Signum {
|
|||
/// ```
|
||||
pub struct Listener {
|
||||
/// A map from signums to handles to keep the handles in memory
|
||||
handles: ~[(Signum, ~RtioSignal:Send)],
|
||||
handles: Vec<(Signum, ~RtioSignal:Send)>,
|
||||
/// This is where all the handles send signums, which are received by
|
||||
/// the clients from the receiver.
|
||||
tx: Sender<Signum>,
|
||||
|
|
@ -99,7 +100,7 @@ impl Listener {
|
|||
Listener {
|
||||
tx: tx,
|
||||
rx: rx,
|
||||
handles: ~[],
|
||||
handles: vec!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ use mem::replace;
|
|||
use option::{None, Option, Some};
|
||||
use rt::task::{Task, LocalStorage};
|
||||
use slice::{ImmutableVector, MutableVector, OwnedVector};
|
||||
use vec::Vec;
|
||||
|
||||
/**
|
||||
* Indexes a task-local data slot. This pointer is used for comparison to
|
||||
|
|
@ -89,7 +90,7 @@ impl<T: 'static> LocalData for T {}
|
|||
// n.b. If TLS is used heavily in future, this could be made more efficient with
|
||||
// a proper map.
|
||||
#[doc(hidden)]
|
||||
pub type Map = ~[Option<(*u8, TLSValue, LoanState)>];
|
||||
pub type Map = Vec<Option<(*u8, TLSValue, LoanState)>>;
|
||||
type TLSValue = ~LocalData:Send;
|
||||
|
||||
// Gets the map from the runtime. Lazily initialises if not done so already.
|
||||
|
|
@ -106,7 +107,7 @@ unsafe fn get_local_map() -> &mut Map {
|
|||
// If this is the first time we've accessed TLS, perform similar
|
||||
// actions to the oldsched way of doing things.
|
||||
&LocalStorage(ref mut slot) => {
|
||||
*slot = Some(~[]);
|
||||
*slot = Some(vec!());
|
||||
match *slot {
|
||||
Some(ref mut map_ptr) => { return map_ptr }
|
||||
None => abort()
|
||||
|
|
@ -237,7 +238,7 @@ fn get_with<T:'static,
|
|||
Some(i) => {
|
||||
let ret;
|
||||
let mut return_loan = false;
|
||||
match map[i] {
|
||||
match *map.get_mut(i) {
|
||||
Some((_, ref data, ref mut loan)) => {
|
||||
match (state, *loan) {
|
||||
(_, NoLoan) => {
|
||||
|
|
@ -271,7 +272,7 @@ fn get_with<T:'static,
|
|||
// in turn relocated the vector. Hence we do another lookup here to
|
||||
// fixup the loans.
|
||||
if return_loan {
|
||||
match map[i] {
|
||||
match *map.get_mut(i) {
|
||||
Some((_, _, ref mut loan)) => { *loan = NoLoan; }
|
||||
None => abort()
|
||||
}
|
||||
|
|
@ -331,7 +332,7 @@ pub fn set<T: 'static>(key: Key<T>, data: T) {
|
|||
// we're not actually sending it to other schedulers or anything.
|
||||
let data: ~LocalData:Send = unsafe { cast::transmute(data) };
|
||||
match insertion_position(map, keyval) {
|
||||
Some(i) => { map[i] = Some((keyval, data, NoLoan)); }
|
||||
Some(i) => { *map.get_mut(i) = Some((keyval, data, NoLoan)); }
|
||||
None => { map.push(Some((keyval, data, NoLoan))); }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ use to_str::ToStr;
|
|||
use slice::{Vector, OwnedVector};
|
||||
use intrinsics::{Disr, Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
|
||||
use raw;
|
||||
use vec::Vec;
|
||||
|
||||
macro_rules! try( ($me:expr, $e:expr) => (
|
||||
match $e {
|
||||
|
|
@ -102,8 +103,8 @@ enum VariantState {
|
|||
|
||||
pub struct ReprVisitor<'a> {
|
||||
ptr: *u8,
|
||||
ptr_stk: ~[*u8],
|
||||
var_stk: ~[VariantState],
|
||||
ptr_stk: Vec<*u8>,
|
||||
var_stk: Vec<VariantState>,
|
||||
writer: &'a mut io::Writer,
|
||||
last_err: Option<io::IoError>,
|
||||
}
|
||||
|
|
@ -112,8 +113,8 @@ pub fn ReprVisitor<'a>(ptr: *u8,
|
|||
writer: &'a mut io::Writer) -> ReprVisitor<'a> {
|
||||
ReprVisitor {
|
||||
ptr: ptr,
|
||||
ptr_stk: ~[],
|
||||
var_stk: ~[],
|
||||
ptr_stk: vec!(),
|
||||
var_stk: vec!(),
|
||||
writer: writer,
|
||||
last_err: None,
|
||||
}
|
||||
|
|
@ -154,8 +155,8 @@ impl<'a> ReprVisitor<'a> {
|
|||
// issues we have to recreate it here.
|
||||
let u = ReprVisitor {
|
||||
ptr: ptr,
|
||||
ptr_stk: ~[],
|
||||
var_stk: ~[],
|
||||
ptr_stk: vec!(),
|
||||
var_stk: vec!(),
|
||||
writer: ::cast::transmute_copy(&self.writer),
|
||||
last_err: None,
|
||||
};
|
||||
|
|
@ -505,7 +506,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
_offset: uint,
|
||||
inner: *TyDesc)
|
||||
-> bool {
|
||||
match self.var_stk[self.var_stk.len() - 1] {
|
||||
match *self.var_stk.get(self.var_stk.len() - 1) {
|
||||
Matched => {
|
||||
if i != 0 {
|
||||
try!(self, self.writer.write(", ".as_bytes()));
|
||||
|
|
@ -523,7 +524,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
_disr_val: Disr,
|
||||
n_fields: uint,
|
||||
_name: &str) -> bool {
|
||||
match self.var_stk[self.var_stk.len() - 1] {
|
||||
match *self.var_stk.get(self.var_stk.len() - 1) {
|
||||
Matched => {
|
||||
if n_fields > 0 {
|
||||
try!(self, self.writer.write([')' as u8]));
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ use option::{Some, None};
|
|||
use ptr::RawPtr;
|
||||
use unstable::sync::Exclusive;
|
||||
use slice::OwnedVector;
|
||||
use vec::Vec;
|
||||
|
||||
type Queue = Exclusive<~[proc():Send]>;
|
||||
type Queue = Exclusive<Vec<proc():Send>>;
|
||||
|
||||
// You'll note that these variables are *not* atomic, and this is done on
|
||||
// purpose. This module is designed to have init() called *once* in a
|
||||
|
|
@ -35,7 +36,7 @@ pub fn init() {
|
|||
unsafe {
|
||||
rtassert!(!RUNNING);
|
||||
rtassert!(QUEUE.is_null());
|
||||
let state: ~Queue = ~Exclusive::new(~[]);
|
||||
let state: ~Queue = ~Exclusive::new(vec!());
|
||||
QUEUE = cast::transmute(state);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +62,7 @@ pub fn run() {
|
|||
QUEUE = 0 as *mut Queue;
|
||||
let mut vec = None;
|
||||
state.with(|arr| {
|
||||
vec = Some(mem::replace(arr, ~[]));
|
||||
vec = Some(mem::replace(arr, vec!()));
|
||||
});
|
||||
vec.take_unwrap()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<T> {
|
|||
/// will only use this structure when allocating a new buffer or deallocating a
|
||||
/// previous one.
|
||||
pub struct BufferPool<T> {
|
||||
pool: Exclusive<~[~Buffer<T>]>,
|
||||
pool: Exclusive<Vec<~Buffer<T>>>,
|
||||
}
|
||||
|
||||
/// 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<T> 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<T> {
|
|||
/// 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<T>, although
|
||||
/// LLVM is probably pretty good at doing this already.
|
||||
struct Buffer<T> {
|
||||
storage: *T,
|
||||
|
|
@ -143,7 +144,7 @@ impl<T: Send> BufferPool<T> {
|
|||
/// Allocates a new buffer pool which in turn can be used to allocate new
|
||||
/// deques.
|
||||
pub fn new() -> BufferPool<T> {
|
||||
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::<Vec<Thread<()>>>();
|
||||
|
||||
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::<Vec<Thread<()>>>();
|
||||
|
||||
for thread in threads.move_iter() {
|
||||
thread.join();
|
||||
|
|
@ -556,7 +557,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
})
|
||||
}).collect::<~[Thread<()>]>();
|
||||
}).collect::<Vec<Thread<()>>>();
|
||||
|
||||
let mut rng = rand::task_rng();
|
||||
let mut expected = 0;
|
||||
|
|
@ -658,4 +659,3 @@ mod tests {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<T> {
|
||||
sequence: AtomicUint,
|
||||
|
|
@ -44,7 +44,7 @@ struct Node<T> {
|
|||
|
||||
struct State<T> {
|
||||
pad0: [u8, ..64],
|
||||
buffer: ~[Node<T>],
|
||||
buffer: Vec<Node<T>>,
|
||||
mask: uint,
|
||||
pad1: [u8, ..64],
|
||||
enqueue_pos: AtomicUint,
|
||||
|
|
@ -69,7 +69,7 @@ impl<T: Send> State<T> {
|
|||
} 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<T: Send> State<T> {
|
|||
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<T: Send> State<T> {
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue