File tree 1 file changed +7
-10
lines changed
1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -102,16 +102,13 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
102
102
let ptr = text. as_ptr ( ) ;
103
103
let usize_bytes = mem:: size_of :: < usize > ( ) ;
104
104
105
- // search to an aligned boundary
106
- let end_align = ( ptr as usize + len) & ( usize_bytes - 1 ) ;
107
- let mut offset;
108
- if end_align > 0 {
109
- offset = if end_align >= len { 0 } else { len - end_align } ;
110
- if let Some ( index) = text[ offset..] . iter ( ) . rposition ( |elt| * elt == x) {
111
- return Some ( offset + index) ;
112
- }
113
- } else {
114
- offset = len;
105
+ let mut offset = {
106
+ // We call this just to obtain the length of the suffix
107
+ let ( _, _, suffix) = unsafe { text. align_to :: < usize > ( ) } ;
108
+ len - suffix. len ( )
109
+ } ;
110
+ if let Some ( index) = text[ offset..] . iter ( ) . rposition ( |elt| * elt == x) {
111
+ return Some ( offset + index) ;
115
112
}
116
113
117
114
// search the body of the text
You can’t perform that action at this time.
0 commit comments