core: Rename ImmutableSlice::unsafe_ref to unsafe_get

Deprecate the previous.
This commit is contained in:
Brian Anderson 2014-08-06 20:08:16 -07:00
parent fbc93082ec
commit 033f28d436
5 changed files with 23 additions and 11 deletions

View File

@ -141,7 +141,7 @@ impl String {
let mut i = 0;
let total = v.len();
fn unsafe_get(xs: &[u8], i: uint) -> u8 {
unsafe { *xs.unsafe_ref(i) }
unsafe { *xs.unsafe_get(i) }
}
fn safe_get(xs: &[u8], i: uint, total: uint) -> u8 {
if i >= total {

View File

@ -926,7 +926,7 @@ macro_rules! iterator_impl {
// such thing as invalid pointers and memory unsafety. The
// reason is performance, without doing this we can get the
// bench_iter_large microbenchmark down to about 30000 ns/iter
// (using .unsafe_ref to index self.stack directly, 38000
// (using .unsafe_get to index self.stack directly, 38000
// ns/iter with [] checked indexing), but this smashes that down
// to 13500 ns/iter.
//

View File

@ -348,7 +348,7 @@ impl<T: Clone> Vec<T> {
unsafe {
ptr::write(
self.as_mut_slice().unsafe_mut_ref(len),
other.unsafe_ref(i).clone());
other.unsafe_get(i).clone());
self.set_len(len + 1);
}
}
@ -703,7 +703,7 @@ impl<T> Vec<T> {
// decrement len before the read(), so a failure on Drop doesn't
// re-drop the just-failed value.
self.len -= 1;
ptr::read(self.as_slice().unsafe_ref(self.len));
ptr::read(self.as_slice().unsafe_get(self.len));
}
}
}
@ -1605,7 +1605,7 @@ impl<T> MutableSeq<T> for Vec<T> {
} else {
unsafe {
self.len -= 1;
Some(ptr::read(self.as_slice().unsafe_ref(self.len())))
Some(ptr::read(self.as_slice().unsafe_get(self.len())))
}
}
}

View File

@ -173,8 +173,14 @@ pub trait ImmutableSlice<'a, T> {
/// Returns a pointer to the element at the given index, without doing
/// bounds checking.
#[deprecated = "renamed to `unsafe_get`"]
unsafe fn unsafe_ref(self, index: uint) -> &'a T;
/// Returns a pointer to the element at the given index, without doing
/// bounds checking.
#[unstable]
unsafe fn unsafe_get(self, index: uint) -> &'a T;
/**
* Returns an unsafe pointer to the vector's buffer
*
@ -351,10 +357,16 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
}
#[inline]
#[deprecated = "renamed to `unsafe_get`"]
unsafe fn unsafe_ref(self, index: uint) -> &'a T {
transmute(self.repr().data.offset(index as int))
}
#[inline]
unsafe fn unsafe_get(self, index: uint) -> &'a T {
transmute(self.repr().data.offset(index as int))
}
#[inline]
fn as_ptr(&self) -> *const T {
self.repr().data

View File

@ -348,7 +348,7 @@ impl Isaac64Rng {
static MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)];
macro_rules! ind (
($x:expr) => {
*self.mem.unsafe_ref(($x as uint >> 3) & (RAND_SIZE_64 - 1))
*self.mem.unsafe_get(($x as uint >> 3) & (RAND_SIZE_64 - 1))
}
);
@ -362,8 +362,8 @@ impl Isaac64Rng {
let mix = if $j == 0 {!mix} else {mix};
unsafe {
let x = *self.mem.unsafe_ref(base + mr_offset);
a = mix + *self.mem.unsafe_ref(base + m2_offset);
let x = *self.mem.unsafe_get(base + mr_offset);
a = mix + *self.mem.unsafe_get(base + m2_offset);
let y = ind!(x) + a + b;
self.mem.unsafe_set(base + mr_offset, y);
@ -379,8 +379,8 @@ impl Isaac64Rng {
let mix = if $j == 0 {!mix} else {mix};
unsafe {
let x = *self.mem.unsafe_ref(base + mr_offset);
a = mix + *self.mem.unsafe_ref(base + m2_offset);
let x = *self.mem.unsafe_get(base + mr_offset);
a = mix + *self.mem.unsafe_get(base + m2_offset);
let y = ind!(x) + a + b;
self.mem.unsafe_set(base + mr_offset, y);
@ -416,7 +416,7 @@ impl Rng for Isaac64Rng {
self.isaac64();
}
self.cnt -= 1;
unsafe { *self.rsl.unsafe_ref(self.cnt) }
unsafe { *self.rsl.unsafe_get(self.cnt) }
}
}