Skip to content

Use raw pointer casts for slice, str's .as_ptr() #31999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ impl<T> SliceExt for [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
Expand Down Expand Up @@ -448,12 +448,12 @@ impl<T> SliceExt for [T] {

#[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]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ impl StrExt for str {

#[inline]
fn as_ptr(&self) -> *const u8 {
self.repr().data
self as *const str as *const u8
}

#[inline]
Expand Down