File tree 2 files changed +6
-8
lines changed
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 {
646
646
/// Accessing adjacent `u8` as `u16`
647
647
///
648
648
/// ```
649
- /// # #![feature(core_intrinsics )]
649
+ /// # #![feature(align_offset )]
650
650
/// # fn foo(n: usize) {
651
651
/// # use std::mem::align_of;
652
652
/// # unsafe {
@@ -875,7 +875,7 @@ impl<T: ?Sized> *mut T {
875
875
/// Accessing adjacent `u8` as `u16`
876
876
///
877
877
/// ```
878
- /// # #![feature(core_intrinsics )]
878
+ /// # #![feature(align_offset )]
879
879
/// # fn foo(n: usize) {
880
880
/// # use std::mem::align_of;
881
881
/// # unsafe {
Original file line number Diff line number Diff line change 15
15
pub mod fallback {
16
16
use cmp;
17
17
use mem;
18
+ use intrinsics:: align_offset;
18
19
19
20
const LO_U64 : u64 = 0x0101010101010101 ;
20
21
const HI_U64 : u64 = 0x8080808080808080 ;
@@ -65,15 +66,12 @@ pub mod fallback {
65
66
let usize_bytes = mem:: size_of :: < usize > ( ) ;
66
67
67
68
// 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) ;
72
72
if let Some ( index) = text[ ..offset] . iter ( ) . position ( |elt| * elt == x) {
73
73
return Some ( index) ;
74
74
}
75
- } else {
76
- offset = 0 ;
77
75
}
78
76
79
77
// search the body of the text
You can’t perform that action at this time.
0 commit comments