File tree Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -646,7 +646,7 @@ impl<T: ?Sized> *const T {
646646 /// Accessing adjacent `u8` as `u16`
647647 ///
648648 /// ```
649- /// # #![feature(core_intrinsics )]
649+ /// # #![feature(align_offset )]
650650 /// # fn foo(n: usize) {
651651 /// # use std::mem::align_of;
652652 /// # unsafe {
@@ -875,7 +875,7 @@ impl<T: ?Sized> *mut T {
875875 /// Accessing adjacent `u8` as `u16`
876876 ///
877877 /// ```
878- /// # #![feature(core_intrinsics )]
878+ /// # #![feature(align_offset )]
879879 /// # fn foo(n: usize) {
880880 /// # use std::mem::align_of;
881881 /// # unsafe {
Original file line number Diff line number Diff line change 1515pub mod fallback {
1616 use cmp;
1717 use mem;
18+ use intrinsics:: align_offset;
1819
1920 const LO_U64 : u64 = 0x0101010101010101 ;
2021 const HI_U64 : u64 = 0x8080808080808080 ;
@@ -65,15 +66,12 @@ pub mod fallback {
6566 let usize_bytes = mem:: size_of :: < usize > ( ) ;
6667
6768 // search up to an aligned boundary
68- let align = ( ptr as usize ) & ( usize_bytes- 1 ) ;
69- let mut offset;
70- if align > 0 {
71- offset = cmp:: min ( usize_bytes - align, len) ;
69+ let mut offset = unsafe { align_offset ( ptr as * const _ , usize_bytes) } ;
70+ if offset > 0 {
71+ offset = cmp:: min ( offset, len) ;
7272 if let Some ( index) = text[ ..offset] . iter ( ) . position ( |elt| * elt == x) {
7373 return Some ( index) ;
7474 }
75- } else {
76- offset = 0 ;
7775 }
7876
7977 // search the body of the text
You can’t perform that action at this time.
0 commit comments