Skip to content

Commit 7ccb0e6

Browse files
committed
core: Remove uses of DVec in io/repr
1 parent 647a94d commit 7ccb0e6

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

src/libcore/io.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Basic input/output
1616

1717
use result::Result;
1818

19-
use dvec::DVec;
2019
use int;
2120
use libc;
2221
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); }
11091108
pub fn println(s: &str) { stdout().write_line(s); }
11101109
11111110
pub struct BytesWriter {
1112-
bytes: DVec<u8>,
1111+
mut bytes: ~[u8],
11131112
mut pos: uint,
11141113
}
11151114
11161115
impl Writer for BytesWriter {
11171116
fn write(&self, v: &[const u8]) {
1118-
do self.bytes.swap |bytes| {
1119-
let mut bytes = bytes;
1120-
let v_len = v.len();
1121-
let bytes_len = bytes.len();
1122-
1123-
let count = uint::max(bytes_len, self.pos + v_len);
1124-
vec::reserve(&mut bytes, count);
1125-
unsafe { vec::raw::set_len(&mut bytes, count); }
1126-
1127-
{
1128-
let view = vec::mut_slice(bytes, self.pos, count);
1129-
vec::bytes::copy_memory(view, v, v_len);
1130-
}
1117+
let v_len = v.len();
1118+
let bytes_len = self.bytes.len();
11311119
1132-
self.pos += v_len;
1120+
let count = uint::max(bytes_len, self.pos + v_len);
1121+
vec::reserve(&mut self.bytes, count);
11331122
1134-
bytes
1123+
unsafe {
1124+
vec::raw::set_len(&mut self.bytes, count);
1125+
let view = vec::mut_slice(self.bytes, self.pos, count);
1126+
vec::bytes::copy_memory(view, v, v_len);
11351127
}
1128+
1129+
self.pos += v_len;
11361130
}
11371131
fn seek(&self, offset: int, whence: SeekStyle) {
11381132
let pos = self.pos;
@@ -1145,14 +1139,14 @@ impl Writer for BytesWriter {
11451139
}
11461140
11471141
pub pure fn BytesWriter() -> BytesWriter {
1148-
BytesWriter { bytes: DVec(), mut pos: 0u }
1142+
BytesWriter { bytes: ~[], mut pos: 0u }
11491143
}
11501144
11511145
pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
11521146
let wr = @BytesWriter();
11531147
f(wr as Writer);
1154-
// FIXME (#3758): This should not be needed.
1155-
unsafe { wr.bytes.check_out(|bytes| bytes) }
1148+
let @BytesWriter{bytes, _} = wr;
1149+
return bytes;
11561150
}
11571151
11581152
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {

src/libcore/repr.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ More runtime type reflection
1616

1717
use cast::transmute;
1818
use char;
19-
use dvec::DVec;
2019
use intrinsic;
2120
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
2221
use io::{Writer, WriterUtil};
@@ -147,14 +146,14 @@ enum VariantState {
147146

148147
pub struct ReprVisitor {
149148
mut ptr: *c_void,
150-
ptr_stk: DVec<*c_void>,
151-
var_stk: DVec<VariantState>,
149+
mut ptr_stk: ~[*c_void],
150+
mut var_stk: ~[VariantState],
152151
writer: @Writer
153152
}
154153
pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor {
155154
ReprVisitor { ptr: ptr,
156-
ptr_stk: DVec(),
157-
var_stk: DVec(),
155+
ptr_stk: ~[],
156+
var_stk: ~[],
158157
writer: writer }
159158
}
160159

@@ -500,7 +499,7 @@ impl TyVisitor for ReprVisitor {
500499
}
501500

502501
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
503-
match self.var_stk.last() {
502+
match self.var_stk[self.var_stk.len() - 1] {
504503
Degenerate | TagMatch => {
505504
if i != 0 {
506505
self.writer.write_str(", ");
@@ -518,7 +517,7 @@ impl TyVisitor for ReprVisitor {
518517
_disr_val: int,
519518
n_fields: uint,
520519
_name: &str) -> bool {
521-
match self.var_stk.last() {
520+
match self.var_stk[self.var_stk.len() - 1] {
522521
Degenerate | TagMatch => {
523522
if n_fields > 0 {
524523
self.writer.write_char(')');

src/libcore/task/local_data_priv.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use cast;
1414
use cmp::Eq;
15-
use dvec;
1615
use libc;
1716
use option;
1817
use prelude::*;
@@ -35,11 +34,11 @@ impl Eq for LocalData {
3534
pure fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) }
3635
}
3736

38-
// We use dvec because it's the best data structure in core. If TLS is used
39-
// heavily in future, this could be made more efficient with a proper map.
37+
// If TLS is used heavily in future, this could be made more efficient with a
38+
// proper map.
4039
type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
4140
// Has to be a pointer at outermost layer; the foreign call returns void *.
42-
type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
41+
type TaskLocalMap = @mut ~[Option<TaskLocalElement>];
4342

4443
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) {
4544
unsafe {
@@ -60,17 +59,21 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
6059
// drop when they finish. No "re-storing after modifying" is needed.
6160
let map_ptr = rt::rust_get_task_local_data(task);
6261
if map_ptr.is_null() {
63-
let map: TaskLocalMap = @dvec::DVec();
62+
let map: TaskLocalMap = @mut ~[];
6463
// Use reinterpret_cast -- transmute would take map away from us also.
6564
rt::rust_set_task_local_data(
6665
task, cast::reinterpret_cast(&map));
6766
rt::rust_task_local_data_atexit(task, cleanup_task_local_map);
6867
// Also need to reference it an extra time to keep it for now.
69-
cast::bump_box_refcount(map);
68+
let nonmut = cast::transmute::<TaskLocalMap,
69+
@~[Option<TaskLocalElement>]>(map);
70+
cast::bump_box_refcount(nonmut);
7071
map
7172
} else {
7273
let map = cast::transmute(map_ptr);
73-
cast::bump_box_refcount(map);
74+
let nonmut = cast::transmute::<TaskLocalMap,
75+
@~[Option<TaskLocalElement>]>(map);
76+
cast::bump_box_refcount(nonmut);
7477
map
7578
}
7679
}
@@ -118,7 +121,7 @@ unsafe fn local_get_helper<T:Durable>(
118121
let data: @T = cast::transmute(data_ptr);
119122
cast::bump_box_refcount(data);
120123
if do_pop {
121-
(*map).set_elt(index, None);
124+
map[index] = None;
122125
}
123126
data
124127
}
@@ -159,13 +162,13 @@ pub unsafe fn local_set<T:Durable>(
159162
Some((index, _old_data_ptr)) => {
160163
// Key already had a value set, _old_data_ptr, whose reference
161164
// will get dropped when the local_data box is overwritten.
162-
(*map).set_elt(index, new_entry);
165+
map[index] = new_entry;
163166
}
164167
None => {
165168
// Find an empty slot. If not, grow the vector.
166169
match (*map).position(|x| x.is_none()) {
167-
Some(empty_index) => (*map).set_elt(empty_index, new_entry),
168-
None => (*map).push(new_entry)
170+
Some(empty_index) => { map[empty_index] = new_entry; }
171+
None => { map.push(new_entry); }
169172
}
170173
}
171174
}

0 commit comments

Comments
 (0)