Skip to content

Commit 14fdeca

Browse files
committed
---
yaml --- r: 24166 b: refs/heads/master c: 264e1b2 h: refs/heads/master v: v3
1 parent 86d30cf commit 14fdeca

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a7db161eed68566db4ab8502f73e397fdf6b8e7c
2+
refs/heads/master: 264e1b2edbba5fcb4dc0866fa168f434fe54876b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/at_vec.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#[forbid(deprecated_mode)];
55
#[forbid(deprecated_pattern)];
66

7+
use cast::transmute;
78
use ptr::addr_of;
89

910
/// Code for dealing with @-vectors. This is pretty incomplete, and
@@ -48,10 +49,10 @@ pub pure fn capacity<T>(v: @[const T]) -> uint {
4849
#[inline(always)]
4950
pub pure fn build_sized<A>(size: uint,
5051
builder: &fn(push: pure fn(+v: A))) -> @[A] {
51-
let mut vec = @[];
52-
unsafe { raw::reserve(vec, size); }
53-
builder(|+x| unsafe { raw::push(vec, move x) });
54-
return vec;
52+
let mut vec: @[const A] = @[];
53+
unsafe { raw::reserve(&mut vec, size); }
54+
builder(|+x| unsafe { raw::push(&mut vec, move x) });
55+
return unsafe { transmute(vec) };
5556
}
5657

5758
/**
@@ -125,10 +126,10 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
125126
* Creates an immutable vector of size `n_elts` and initializes the elements
126127
* to the value `t`.
127128
*/
128-
pub pure fn from_elem<T: Copy>(n_elts: uint, t: &T) -> @[T] {
129+
pub pure fn from_elem<T: Copy>(n_elts: uint, +t: T) -> @[T] {
129130
do build_sized(n_elts) |push| {
130131
let mut i: uint = 0u;
131-
while i < n_elts { push(copy *t); i += 1u; }
132+
while i < n_elts { push(copy t); i += 1u; }
132133
}
133134
}
134135

@@ -165,8 +166,8 @@ pub mod raw {
165166
}
166167

167168
#[inline(always)]
168-
pub unsafe fn push<T>(v: @[const T], +initval: T) {
169-
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
169+
pub unsafe fn push<T>(v: &mut @[const T], +initval: T) {
170+
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
170171
let fill = (**repr).unboxed.fill;
171172
if (**repr).unboxed.alloc > fill {
172173
push_fast(v, move initval);
@@ -177,16 +178,16 @@ pub mod raw {
177178
}
178179
// This doesn't bother to make sure we have space.
179180
#[inline(always)] // really pretty please
180-
pub unsafe fn push_fast<T>(v: @[const T], +initval: T) {
181-
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
181+
pub unsafe fn push_fast<T>(v: &mut @[const T], +initval: T) {
182+
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
182183
let fill = (**repr).unboxed.fill;
183184
(**repr).unboxed.fill += sys::size_of::<T>();
184185
let p = ptr::addr_of((**repr).unboxed.data);
185186
let p = ptr::offset(p, fill) as *mut T;
186187
rusti::move_val_init(*p, move initval);
187188
}
188189

189-
pub unsafe fn push_slow<T>(v: @[const T], +initval: T) {
190+
pub unsafe fn push_slow<T>(v: &mut @[const T], +initval: T) {
190191
reserve_at_least(v, v.len() + 1u);
191192
push_fast(v, move initval);
192193
}
@@ -202,10 +203,10 @@ pub mod raw {
202203
* * v - A vector
203204
* * n - The number of elements to reserve space for
204205
*/
205-
pub unsafe fn reserve<T>(v: @[const T], n: uint) {
206+
pub unsafe fn reserve<T>(v: &mut @[const T], n: uint) {
206207
// Only make the (slow) call into the runtime if we have to
207-
if capacity(v) < n {
208-
let ptr = addr_of(v) as **VecRepr;
208+
if capacity(*v) < n {
209+
let ptr: **VecRepr = transmute(copy v);
209210
rustrt::vec_reserve_shared_actual(sys::get_type_desc::<T>(),
210211
ptr, n as libc::size_t);
211212
}
@@ -226,7 +227,7 @@ pub mod raw {
226227
* * v - A vector
227228
* * n - The number of elements to reserve space for
228229
*/
229-
pub unsafe fn reserve_at_least<T>(v: @[const T], n: uint) {
230+
pub unsafe fn reserve_at_least<T>(v: &mut @[const T], n: uint) {
230231
reserve(v, uint::next_power_of_two(n));
231232
}
232233

trunk/src/libstd/arena.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ struct Arena {
7070
}
7171

7272
fn chunk(size: uint, is_pod: bool) -> Chunk {
73-
let mut v = @[];
74-
unsafe { at_vec::raw::reserve(v, size); }
75-
{ data: v, mut fill: 0u, is_pod: is_pod }
73+
let mut v: @[const u8] = @[];
74+
unsafe { at_vec::raw::reserve(&mut v, size); }
75+
{ data: unsafe { cast::transmute(v) }, mut fill: 0u, is_pod: is_pod }
7676
}
7777

7878
fn arena_with_size(initial_size: uint) -> Arena {

0 commit comments

Comments
 (0)