File tree 1 file changed +3
-6
lines changed
1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change @@ -1422,6 +1422,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
1422
1422
let usize_bytes = mem:: size_of :: < usize > ( ) ;
1423
1423
let ascii_block_size = 2 * usize_bytes;
1424
1424
let blocks_end = if len >= ascii_block_size { len - ascii_block_size + 1 } else { 0 } ;
1425
+ let align = v. as_ptr ( ) . align_offset ( usize_bytes) ;
1425
1426
1426
1427
while index < len {
1427
1428
let old_offset = index;
@@ -1501,12 +1502,8 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
1501
1502
// Ascii case, try to skip forward quickly.
1502
1503
// When the pointer is aligned, read 2 words of data per iteration
1503
1504
// until we find a word containing a non-ascii byte.
1504
- let ptr = v. as_ptr ( ) ;
1505
- let align = unsafe {
1506
- // the offset is safe, because `index` is guaranteed inbounds
1507
- ptr. add ( index) . align_offset ( usize_bytes)
1508
- } ;
1509
- if align == 0 {
1505
+ if align. wrapping_sub ( index) % usize_bytes == 0 {
1506
+ let ptr = v. as_ptr ( ) ;
1510
1507
while index < blocks_end {
1511
1508
unsafe {
1512
1509
let block = ptr. add ( index) as * const usize ;
You can’t perform that action at this time.
0 commit comments