Skip to content

Commit 033f28d

Browse files
committed
core: Rename ImmutableSlice::unsafe_ref to unsafe_get
Deprecate the previous.
1 parent fbc9308 commit 033f28d

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

src/libcollections/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl String {
141141
let mut i = 0;
142142
let total = v.len();
143143
fn unsafe_get(xs: &[u8], i: uint) -> u8 {
144-
unsafe { *xs.unsafe_ref(i) }
144+
unsafe { *xs.unsafe_get(i) }
145145
}
146146
fn safe_get(xs: &[u8], i: uint, total: uint) -> u8 {
147147
if i >= total {

src/libcollections/trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ macro_rules! iterator_impl {
926926
// such thing as invalid pointers and memory unsafety. The
927927
// reason is performance, without doing this we can get the
928928
// bench_iter_large microbenchmark down to about 30000 ns/iter
929-
// (using .unsafe_ref to index self.stack directly, 38000
929+
// (using .unsafe_get to index self.stack directly, 38000
930930
// ns/iter with [] checked indexing), but this smashes that down
931931
// to 13500 ns/iter.
932932
//

src/libcollections/vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<T: Clone> Vec<T> {
348348
unsafe {
349349
ptr::write(
350350
self.as_mut_slice().unsafe_mut_ref(len),
351-
other.unsafe_ref(i).clone());
351+
other.unsafe_get(i).clone());
352352
self.set_len(len + 1);
353353
}
354354
}
@@ -703,7 +703,7 @@ impl<T> Vec<T> {
703703
// decrement len before the read(), so a failure on Drop doesn't
704704
// re-drop the just-failed value.
705705
self.len -= 1;
706-
ptr::read(self.as_slice().unsafe_ref(self.len));
706+
ptr::read(self.as_slice().unsafe_get(self.len));
707707
}
708708
}
709709
}
@@ -1605,7 +1605,7 @@ impl<T> MutableSeq<T> for Vec<T> {
16051605
} else {
16061606
unsafe {
16071607
self.len -= 1;
1608-
Some(ptr::read(self.as_slice().unsafe_ref(self.len())))
1608+
Some(ptr::read(self.as_slice().unsafe_get(self.len())))
16091609
}
16101610
}
16111611
}

src/libcore/slice.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,14 @@ pub trait ImmutableSlice<'a, T> {
173173

174174
/// Returns a pointer to the element at the given index, without doing
175175
/// bounds checking.
176+
#[deprecated = "renamed to `unsafe_get`"]
176177
unsafe fn unsafe_ref(self, index: uint) -> &'a T;
177178

179+
/// Returns a pointer to the element at the given index, without doing
180+
/// bounds checking.
181+
#[unstable]
182+
unsafe fn unsafe_get(self, index: uint) -> &'a T;
183+
178184
/**
179185
* Returns an unsafe pointer to the vector's buffer
180186
*
@@ -351,10 +357,16 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
351357
}
352358

353359
#[inline]
360+
#[deprecated = "renamed to `unsafe_get`"]
354361
unsafe fn unsafe_ref(self, index: uint) -> &'a T {
355362
transmute(self.repr().data.offset(index as int))
356363
}
357364

365+
#[inline]
366+
unsafe fn unsafe_get(self, index: uint) -> &'a T {
367+
transmute(self.repr().data.offset(index as int))
368+
}
369+
358370
#[inline]
359371
fn as_ptr(&self) -> *const T {
360372
self.repr().data

src/librand/isaac.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl Isaac64Rng {
348348
static MP_VEC: [(uint, uint), .. 2] = [(0,MIDPOINT), (MIDPOINT, 0)];
349349
macro_rules! ind (
350350
($x:expr) => {
351-
*self.mem.unsafe_ref(($x as uint >> 3) & (RAND_SIZE_64 - 1))
351+
*self.mem.unsafe_get(($x as uint >> 3) & (RAND_SIZE_64 - 1))
352352
}
353353
);
354354

@@ -362,8 +362,8 @@ impl Isaac64Rng {
362362
let mix = if $j == 0 {!mix} else {mix};
363363

364364
unsafe {
365-
let x = *self.mem.unsafe_ref(base + mr_offset);
366-
a = mix + *self.mem.unsafe_ref(base + m2_offset);
365+
let x = *self.mem.unsafe_get(base + mr_offset);
366+
a = mix + *self.mem.unsafe_get(base + m2_offset);
367367
let y = ind!(x) + a + b;
368368
self.mem.unsafe_set(base + mr_offset, y);
369369

@@ -379,8 +379,8 @@ impl Isaac64Rng {
379379
let mix = if $j == 0 {!mix} else {mix};
380380

381381
unsafe {
382-
let x = *self.mem.unsafe_ref(base + mr_offset);
383-
a = mix + *self.mem.unsafe_ref(base + m2_offset);
382+
let x = *self.mem.unsafe_get(base + mr_offset);
383+
a = mix + *self.mem.unsafe_get(base + m2_offset);
384384
let y = ind!(x) + a + b;
385385
self.mem.unsafe_set(base + mr_offset, y);
386386

@@ -416,7 +416,7 @@ impl Rng for Isaac64Rng {
416416
self.isaac64();
417417
}
418418
self.cnt -= 1;
419-
unsafe { *self.rsl.unsafe_ref(self.cnt) }
419+
unsafe { *self.rsl.unsafe_get(self.cnt) }
420420
}
421421
}
422422

0 commit comments

Comments
 (0)