Making vec::reserve reserve precisely the size given (untested)

This commit is contained in:
Kevin Cantu 2012-02-04 03:16:59 -08:00 committed by Brian Anderson
parent 9f0239ce9c
commit d3dfe8758d
2 changed files with 8 additions and 6 deletions

View File

@ -102,7 +102,7 @@ extern "C" CDECL void
vec_reserve_shared(type_desc* ty, rust_vec** vp,
size_t n_elts) {
rust_task *task = rust_task_thread::get_task();
reserve_vec(task, vp, n_elts * ty->size);
reserve_vec_exact(task, vp, n_elts * ty->size);
}
/**

View File

@ -178,15 +178,17 @@ inline size_t vec_size(size_t elems) {
return sizeof(rust_vec) + sizeof(T) * elems;
}
inline void reserve_vec(rust_task* task, rust_vec** vpp, size_t size) {
inline void reserve_vec_exact(rust_task* task, rust_vec** vpp, size_t size) {
if (size > (*vpp)->alloc) {
size_t new_alloc = next_power_of_two(size);
*vpp = (rust_vec*)task->kernel->realloc(*vpp, new_alloc +
sizeof(rust_vec));
(*vpp)->alloc = new_alloc;
*vpp = (rust_vec*)task->kernel->realloc(*vpp, size + sizeof(rust_vec));
(*vpp)->alloc = size;
}
}
inline void reserve_vec(rust_task* task, rust_vec** vpp, size_t size) {
reserve_vec_exact(task, vpp, next_power_of_two(size));
}
typedef rust_vec rust_str;
inline rust_str *