libcore: rewrite vec::unsafe::from_buf in pure rust

This commit is contained in:
Erick Tryzelaar 2012-08-25 16:53:44 -07:00
parent 536cb90a21
commit 0e1a4a4da2
3 changed files with 7 additions and 25 deletions

View file

@ -148,22 +148,6 @@ str_reserve_shared(rust_vec_box** sp,
reserve_vec_exact(task, sp, n_elts + 1);
}
/**
* Copies elements in an unsafe buffer to the given interior vector. The
* vector must have size zero.
*/
extern "C" CDECL rust_vec_box*
vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) {
rust_task *task = rust_get_current_task();
size_t fill = ty->size * count;
rust_vec_box* v = (rust_vec_box*)
task->kernel->malloc(fill + sizeof(rust_vec_box),
"vec_from_buf");
v->body.fill = v->body.alloc = fill;
memmove(&v->body.data[0], ptr, fill);
return v;
}
extern "C" CDECL void
rust_str_push(rust_vec_box** sp, uint8_t byte) {
rust_task *task = rust_get_current_task();
@ -515,8 +499,9 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
out_tm->tm_nsec = nsec;
if (zone != NULL) {
rust_task *task = rust_get_current_task();
size_t size = strlen(zone);
str_reserve_shared(&out_tm->tm_zone, size);
reserve_vec_exact(task, &out_tm->tm_zone, size + 1);
memcpy(out_tm->tm_zone->body.data, zone, size);
out_tm->tm_zone->body.fill = size + 1;
out_tm->tm_zone->body.data[size] = '\0';