File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Expand file tree Collapse file tree 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> {
102102 let ptr = text. as_ptr ( ) ;
103103 let usize_bytes = mem:: size_of :: < usize > ( ) ;
104104
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) ;
115112 }
116113
117114 // search the body of the text
You can’t perform that action at this time.
0 commit comments