From 033f28d4364e0bd0ff7031b67e6bd0356fe00bfd Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 6 Aug 2014 20:08:16 -0700 Subject: [PATCH] core: Rename ImmutableSlice::unsafe_ref to unsafe_get Deprecate the previous. --- src/libcollections/string.rs | 2 +- src/libcollections/trie.rs | 2 +- src/libcollections/vec.rs | 6 +++--- src/libcore/slice.rs | 12 ++++++++++++ src/librand/isaac.rs | 12 ++++++------ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index d8cc80fdf41d..3b9e2ac72dc4 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -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 { diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index c3dcebfc815b..dcfe25680746 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -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. // diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 78809e32fe9c..fd069f547271 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -348,7 +348,7 @@ impl Vec { 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 Vec { // 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 MutableSeq for Vec { } 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()))) } } } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 3a619b45e53a..8d5743767195 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -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 diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 134e7af50701..2fbfa6d6e85a 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -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) } } }