]> git.lizzy.rs Git - rust.git/commitdiff
Use raw pointer casts for slice, str's .as_ptr()
authorUlrik Sverdrup <bluss@users.noreply.github.com>
Tue, 1 Mar 2016 19:21:55 +0000 (20:21 +0100)
committerUlrik Sverdrup <bluss@users.noreply.github.com>
Tue, 1 Mar 2016 21:30:18 +0000 (22:30 +0100)
We can now use raw pointer casts `*const [T] as *const T` and
`*const str as *const u8` instead of .repr() for getting the
pointer out of a slice.

src/libcore/slice.rs
src/libcore/str/mod.rs

index afda70f4fcc0af67b8d44853f7002ce071fe1339..fb15533f33c5405221d5653d4f73760a70e2bece 100644 (file)
@@ -285,12 +285,12 @@ fn last(&self) -> Option<&T> {
 
     #[inline]
     unsafe fn get_unchecked(&self, index: usize) -> &T {
-        &*(self.repr().data.offset(index as isize))
+        &*(self.as_ptr().offset(index as isize))
     }
 
     #[inline]
     fn as_ptr(&self) -> *const T {
-        self.repr().data
+        self as *const [T] as *const T
     }
 
     fn binary_search_by<F>(&self, mut f: F) -> Result<usize, usize> where
@@ -448,12 +448,12 @@ fn reverse(&mut self) {
 
     #[inline]
     unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T {
-        &mut *(self.repr().data as *mut T).offset(index as isize)
+        &mut *self.as_mut_ptr().offset(index as isize)
     }
 
     #[inline]
     fn as_mut_ptr(&mut self) -> *mut T {
-        self.repr().data as *mut T
+        self as *mut [T] as *mut T
     }
 
     #[inline]
index 4d367cfd432f94a2f5333ec3bbbcdc94b33b493c..a555b8592912ee9ff4eb127d715eb0c30b1994e4 100644 (file)
@@ -1894,7 +1894,7 @@ fn slice_shift_char(&self) -> Option<(char, &str)> {
 
     #[inline]
     fn as_ptr(&self) -> *const u8 {
-        self.repr().data
+        self as *const str as *const u8
     }
 
     #[inline]