diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2011-06-16 10:32:52 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2011-06-16 10:32:52 -0700 |
| commit | f9da8b2676c192e7a1ad68c719b84edf1b52ccb7 (patch) | |
| tree | 5a7251407d7b25e63cf1d0f45a5243a85b844c81 /src/rt/rust_builtin.cpp | |
| parent | 66c52036dabdeba6f28dcc0401d5a64c232e35d7 (diff) | |
| download | rust-f9da8b2676c192e7a1ad68c719b84edf1b52ccb7.tar.gz rust-f9da8b2676c192e7a1ad68c719b84edf1b52ccb7.zip | |
rt: Add an ivec length intrinsic and an ivec reserve function, both untested as of yet
Diffstat (limited to 'src/rt/rust_builtin.cpp')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 3500743a79e..2437a5c364d 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -576,6 +576,37 @@ get_time(rust_task *task, uint32_t *sec, uint32_t *usec) { } #endif +/** + * Preallocates the exact number of bytes in the given interior vector. + */ +extern "C" void +ivec_reserve(rust_task *task, type_desc *ty, rust_ivec *v, size_t n_elems) +{ + size_t new_alloc = n_elems * ty->size; + if (new_alloc <= v->alloc) + return; // Already big enough. + + rust_ivec_heap *heap_part; + if (v->fill) { + // On stack; spill to heap. + heap_part = (rust_ivec_heap *)task->malloc(new_alloc + + sizeof(size_t)); + heap_part->fill = v->fill; + memcpy(&heap_part->data, v->payload.data, v->fill); + + v->fill = 0; + v->payload.ptr = heap_part; + } else { + // On heap; resize. + heap_part = (rust_ivec_heap *)task->realloc(v->payload.ptr, + new_alloc); + v->payload.ptr = heap_part; + } + + v->alloc = new_alloc; +} + + // // Local Variables: // mode: C++ |
