diff --git a/src/libcore/io.rs b/src/libcore/io.rs index cc40b90d61a..34fa4c972ea 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -16,7 +16,6 @@ Basic input/output use result::Result; -use dvec::DVec; use int; use libc; use libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t}; @@ -1109,30 +1108,25 @@ pub fn print(s: &str) { stdout().write_str(s); } pub fn println(s: &str) { stdout().write_line(s); } pub struct BytesWriter { - bytes: DVec, + mut bytes: ~[u8], mut pos: uint, } impl Writer for BytesWriter { fn write(&self, v: &[const u8]) { - do self.bytes.swap |bytes| { - let mut bytes = bytes; - let v_len = v.len(); - let bytes_len = bytes.len(); + let v_len = v.len(); + let bytes_len = self.bytes.len(); - let count = uint::max(bytes_len, self.pos + v_len); - vec::reserve(&mut bytes, count); - unsafe { vec::raw::set_len(&mut bytes, count); } + let count = uint::max(bytes_len, self.pos + v_len); + vec::reserve(&mut self.bytes, count); - { - let view = vec::mut_slice(bytes, self.pos, count); - vec::bytes::copy_memory(view, v, v_len); - } - - self.pos += v_len; - - bytes + unsafe { + vec::raw::set_len(&mut self.bytes, count); + let view = vec::mut_slice(self.bytes, self.pos, count); + vec::bytes::copy_memory(view, v, v_len); } + + self.pos += v_len; } fn seek(&self, offset: int, whence: SeekStyle) { let pos = self.pos; @@ -1145,14 +1139,14 @@ impl Writer for BytesWriter { } pub pure fn BytesWriter() -> BytesWriter { - BytesWriter { bytes: DVec(), mut pos: 0u } + BytesWriter { bytes: ~[], mut pos: 0u } } pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] { let wr = @BytesWriter(); f(wr as Writer); - // FIXME (#3758): This should not be needed. - unsafe { wr.bytes.check_out(|bytes| bytes) } + let @BytesWriter{bytes, _} = wr; + return bytes; } pub pure fn with_str_writer(f: fn(Writer)) -> ~str { diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index eaae9d03e8e..e9122754eb4 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -16,7 +16,6 @@ More runtime type reflection use cast::transmute; use char; -use dvec::DVec; use intrinsic; use intrinsic::{TyDesc, TyVisitor, visit_tydesc}; use io::{Writer, WriterUtil}; @@ -147,14 +146,14 @@ enum VariantState { pub struct ReprVisitor { mut ptr: *c_void, - ptr_stk: DVec<*c_void>, - var_stk: DVec, + mut ptr_stk: ~[*c_void], + mut var_stk: ~[VariantState], writer: @Writer } pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor { ReprVisitor { ptr: ptr, - ptr_stk: DVec(), - var_stk: DVec(), + ptr_stk: ~[], + var_stk: ~[], writer: writer } } @@ -500,7 +499,7 @@ impl TyVisitor for ReprVisitor { } fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool { - match self.var_stk.last() { + match self.var_stk[self.var_stk.len() - 1] { Degenerate | TagMatch => { if i != 0 { self.writer.write_str(", "); @@ -518,7 +517,7 @@ impl TyVisitor for ReprVisitor { _disr_val: int, n_fields: uint, _name: &str) -> bool { - match self.var_stk.last() { + match self.var_stk[self.var_stk.len() - 1] { Degenerate | TagMatch => { if n_fields > 0 { self.writer.write_char(')'); diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index cb1283019eb..f035916f594 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -12,7 +12,6 @@ use cast; use cmp::Eq; -use dvec; use libc; use option; use prelude::*; @@ -35,11 +34,11 @@ impl Eq for LocalData { pure fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) } } -// We use dvec because it's the best data structure in core. If TLS is used -// heavily in future, this could be made more efficient with a proper map. +// If TLS is used heavily in future, this could be made more efficient with a +// proper map. type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); // Has to be a pointer at outermost layer; the foreign call returns void *. -type TaskLocalMap = @dvec::DVec>; +type TaskLocalMap = @mut ~[Option]; extern fn cleanup_task_local_map(map_ptr: *libc::c_void) { unsafe { @@ -60,17 +59,21 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { // drop when they finish. No "re-storing after modifying" is needed. let map_ptr = rt::rust_get_task_local_data(task); if map_ptr.is_null() { - let map: TaskLocalMap = @dvec::DVec(); + let map: TaskLocalMap = @mut ~[]; // Use reinterpret_cast -- transmute would take map away from us also. rt::rust_set_task_local_data( task, cast::reinterpret_cast(&map)); rt::rust_task_local_data_atexit(task, cleanup_task_local_map); // Also need to reference it an extra time to keep it for now. - cast::bump_box_refcount(map); + let nonmut = cast::transmute::]>(map); + cast::bump_box_refcount(nonmut); map } else { let map = cast::transmute(map_ptr); - cast::bump_box_refcount(map); + let nonmut = cast::transmute::]>(map); + cast::bump_box_refcount(nonmut); map } } @@ -118,7 +121,7 @@ unsafe fn local_get_helper( let data: @T = cast::transmute(data_ptr); cast::bump_box_refcount(data); if do_pop { - (*map).set_elt(index, None); + map[index] = None; } data } @@ -159,13 +162,13 @@ pub unsafe fn local_set( Some((index, _old_data_ptr)) => { // Key already had a value set, _old_data_ptr, whose reference // will get dropped when the local_data box is overwritten. - (*map).set_elt(index, new_entry); + map[index] = new_entry; } None => { // Find an empty slot. If not, grow the vector. match (*map).position(|x| x.is_none()) { - Some(empty_index) => (*map).set_elt(empty_index, new_entry), - None => (*map).push(new_entry) + Some(empty_index) => { map[empty_index] = new_entry; } + None => { map.push(new_entry); } } } }