Skip to content

Commit 1d25594

Browse files
committed
rustc: Add a vec::alloc_len and fix arena logic to use it
1 parent 5ce3d35 commit 1d25594

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/libcore/vec.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export reserve;
1111
export reserve_at_least;
1212
export capacity;
1313
export len;
14+
export alloc_len;
1415
export from_fn;
1516
export from_elem;
1617
export to_mut;
@@ -153,6 +154,13 @@ pure fn len<T>(&&v: [const T]) -> uint unsafe {
153154
(**repr).fill / sys::size_of::<T>()
154155
}
155156

157+
#[doc = "Returns the number of bytes allocated for this vector"]
158+
#[inline(always)]
159+
pure fn alloc_len<T>(&&v: [const T]) -> uint unsafe {
160+
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
161+
(**repr).alloc
162+
}
163+
156164
#[doc = "
157165
Creates and initializes an immutable vector.
158166

src/libstd/arena.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ impl arena for arena {
3030
start = (start + alignm1) & !alignm1;
3131
let mut end = start + n_bytes;
3232

33-
if end > vec::len(head.data) {
33+
if end > vec::alloc_len(head.data) {
3434
// Allocate a new chunk.
35-
let new_min_chunk_size = uint::max(n_bytes, vec::len(head.data));
35+
let new_min_chunk_size = uint::max(n_bytes,
36+
vec::alloc_len(head.data));
3637
head = chunk(uint::next_power_of_two(new_min_chunk_size));
3738
self.chunks = list::cons(head, @self.chunks);
3839
start = 0u;

0 commit comments

Comments
 (0)