rustc: Add a vec::alloc_len and fix arena logic to use it
This commit is contained in:
parent
5ce3d35f41
commit
1d25594657
@ -11,6 +11,7 @@ export reserve;
|
||||
export reserve_at_least;
|
||||
export capacity;
|
||||
export len;
|
||||
export alloc_len;
|
||||
export from_fn;
|
||||
export from_elem;
|
||||
export to_mut;
|
||||
@ -153,6 +154,13 @@ pure fn len<T>(&&v: [const T]) -> uint unsafe {
|
||||
(**repr).fill / sys::size_of::<T>()
|
||||
}
|
||||
|
||||
#[doc = "Returns the number of bytes allocated for this vector"]
|
||||
#[inline(always)]
|
||||
pure fn alloc_len<T>(&&v: [const T]) -> uint unsafe {
|
||||
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
(**repr).alloc
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Creates and initializes an immutable vector.
|
||||
|
||||
|
@ -30,9 +30,10 @@ impl arena for arena {
|
||||
start = (start + alignm1) & !alignm1;
|
||||
let mut end = start + n_bytes;
|
||||
|
||||
if end > vec::len(head.data) {
|
||||
if end > vec::alloc_len(head.data) {
|
||||
// Allocate a new chunk.
|
||||
let new_min_chunk_size = uint::max(n_bytes, vec::len(head.data));
|
||||
let new_min_chunk_size = uint::max(n_bytes,
|
||||
vec::alloc_len(head.data));
|
||||
head = chunk(uint::next_power_of_two(new_min_chunk_size));
|
||||
self.chunks = list::cons(head, @self.chunks);
|
||||
start = 0u;
|
||||
|
Loading…
x
Reference in New Issue
Block a user