File tree Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change @@ -1417,6 +1417,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
14171417 let usize_bytes = mem:: size_of :: < usize > ( ) ;
14181418 let ascii_block_size = 2 * usize_bytes;
14191419 let blocks_end = if len >= ascii_block_size { len - ascii_block_size + 1 } else { 0 } ;
1420+ let align = v. as_ptr ( ) . align_offset ( usize_bytes) ;
14201421
14211422 while index < len {
14221423 let old_offset = index;
@@ -1496,12 +1497,8 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
14961497 // Ascii case, try to skip forward quickly.
14971498 // When the pointer is aligned, read 2 words of data per iteration
14981499 // until we find a word containing a non-ascii byte.
1499- let ptr = v. as_ptr ( ) ;
1500- let align = unsafe {
1501- // the offset is safe, because `index` is guaranteed inbounds
1502- ptr. add ( index) . align_offset ( usize_bytes)
1503- } ;
1504- if align == 0 {
1500+ if align. wrapping_sub ( index) % usize_bytes == 0 {
1501+ let ptr = v. as_ptr ( ) ;
15051502 while index < blocks_end {
15061503 unsafe {
15071504 let block = ptr. add ( index) as * const usize ;
You can’t perform that action at this time.
0 commit comments