rustc: Replace intrinsic vec_len with unsafe Rust code
Preparation for #1981
This commit is contained in:
parent
cce2751461
commit
bc3f5e7160
@ -12,7 +12,6 @@ export memmove;
|
||||
#[abi = "rust-intrinsic"]
|
||||
native mod rusti {
|
||||
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 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"]
|
||||
#[inline(always)]
|
||||
fn offset<T>(ptr: *T, count: uint) -> *T {
|
||||
ret rusti::ptr_offset(ptr, count);
|
||||
fn offset<T>(ptr: *T, count: uint) -> *T unsafe {
|
||||
(ptr as uint + count * sys::size_of::<T>()) as *T
|
||||
}
|
||||
|
||||
#[doc = "Calculate the offset from a mutable pointer"]
|
||||
#[inline(always)]
|
||||
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 u8;
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
native mod rusti {
|
||||
fn vec_len<T>(&&v: [const T]) -> libc::size_t;
|
||||
}
|
||||
|
||||
#[abi = "cdecl"]
|
||||
native mod rustrt {
|
||||
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"]
|
||||
#[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 = "
|
||||
Creates and initializes an immutable vector.
|
||||
|
Loading…
Reference in New Issue
Block a user