From 0e1a4a4da29caadba5d5cd86a5cd2587fdb0755d Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sat, 25 Aug 2012 16:53:44 -0700 Subject: [PATCH] libcore: rewrite vec::unsafe::from_buf in pure rust --- src/libcore/vec.rs | 12 +++++------- src/rt/rust_builtin.cpp | 19 ++----------------- src/rt/rustrt.def.in | 1 - 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 1533b07861c..448678abf7c 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -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(ptr: *T, elts: uint) -> ~[T] { - return ::unsafe::reinterpret_cast( - rustrt::vec_from_buf_shared(sys::get_type_desc::(), - 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 } /** diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index cabc086b64f..a74f5985d36 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -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'; diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index b4db45ab3a0..141937356e6 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -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