rustc: Replace intrinsic vec_len with unsafe Rust code

Preparation for #1981
This commit is contained in:
Marijn Haverbeke
2012-03-21 14:55:36 +01:00
parent cce2751461
commit bc3f5e7160
2 changed files with 7 additions and 10 deletions

View File

@@ -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.