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

@ -102,9 +102,6 @@
fn vec_reserve_shared(++t: *sys::TypeDesc,
++v: **unsafe::VecRepr,
++n: libc::size_t);
fn vec_from_buf_shared(++t: *sys::TypeDesc,
++ptr: *(),
++count: libc::size_t) -> *unsafe::VecRepr;
}
#[abi = "rust-intrinsic"]
@ -1727,10 +1724,11 @@ mod unsafe {
*/
#[inline(always)]
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
return ::unsafe::reinterpret_cast(
rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(),
ptr as *(),
elts as size_t));
let mut dst = ~[];
reserve(dst, elts);
set_len(dst, elts);
as_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts));
dst
}
/**

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';

View File

@ -63,7 +63,6 @@ start_task
vec_reserve_shared_actual
vec_reserve_shared
str_reserve_shared
vec_from_buf_shared
task_clear_event_reject
task_wait_event
task_signal_event