rustc: Replace intrinsic vec_len with unsafe Rust code
Preparation for #1981
This commit is contained in:
@@ -12,7 +12,6 @@ export memmove;
|
|||||||
#[abi = "rust-intrinsic"]
|
#[abi = "rust-intrinsic"]
|
||||||
native mod rusti {
|
native mod rusti {
|
||||||
fn addr_of<T>(val: T) -> *T;
|
fn addr_of<T>(val: T) -> *T;
|
||||||
fn ptr_offset<T>(ptr: *T, count: libc::uintptr_t) -> *T;
|
|
||||||
fn memcpy<T>(dst: *T, src: *T, count: libc::uintptr_t);
|
fn memcpy<T>(dst: *T, src: *T, count: libc::uintptr_t);
|
||||||
fn memmove<T>(dst: *T, src: *T, count: libc::uintptr_t);
|
fn memmove<T>(dst: *T, src: *T, count: libc::uintptr_t);
|
||||||
}
|
}
|
||||||
@@ -29,14 +28,14 @@ fn mut_addr_of<T>(val: T) -> *mutable T unsafe {
|
|||||||
|
|
||||||
#[doc = "Calculate the offset from a pointer"]
|
#[doc = "Calculate the offset from a pointer"]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn offset<T>(ptr: *T, count: uint) -> *T {
|
fn offset<T>(ptr: *T, count: uint) -> *T unsafe {
|
||||||
ret rusti::ptr_offset(ptr, count);
|
(ptr as uint + count * sys::size_of::<T>()) as *T
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = "Calculate the offset from a mutable pointer"]
|
#[doc = "Calculate the offset from a mutable pointer"]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn mut_offset<T>(ptr: *mutable T, count: uint) -> *mutable T {
|
fn mut_offset<T>(ptr: *mutable T, count: uint) -> *mutable T {
|
||||||
ret rusti::ptr_offset(ptr as *T, count) as *mutable T;
|
(ptr as uint + count * sys::size_of::<T>()) as *mutable T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -74,11 +74,6 @@ export vec_len;
|
|||||||
export unsafe;
|
export unsafe;
|
||||||
export u8;
|
export u8;
|
||||||
|
|
||||||
#[abi = "rust-intrinsic"]
|
|
||||||
native mod rusti {
|
|
||||||
fn vec_len<T>(&&v: [const T]) -> libc::size_t;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[abi = "cdecl"]
|
#[abi = "cdecl"]
|
||||||
native mod rustrt {
|
native mod rustrt {
|
||||||
fn vec_reserve_shared<T>(t: *sys::type_desc,
|
fn vec_reserve_shared<T>(t: *sys::type_desc,
|
||||||
@@ -122,7 +117,10 @@ fn reserve<T>(&v: [const T], n: uint) {
|
|||||||
|
|
||||||
#[doc = "Returns the length of a vector"]
|
#[doc = "Returns the length of a vector"]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn len<T>(v: [const T]) -> uint { unchecked { rusti::vec_len(v) } }
|
pure fn len<T>(&&v: [const T]) -> uint unsafe {
|
||||||
|
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||||
|
(**repr).fill / sys::size_of::<T>()
|
||||||
|
}
|
||||||
|
|
||||||
#[doc = "
|
#[doc = "
|
||||||
Creates and initializes an immutable vector.
|
Creates and initializes an immutable vector.
|
||||||
|
|||||||
Reference in New Issue
Block a user