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 @@ -1417,6 +1417,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
1417
1417
let usize_bytes = mem:: size_of :: < usize > ( ) ;
1418
1418
let ascii_block_size = 2 * usize_bytes;
1419
1419
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) ;
1420
1421
1421
1422
while index < len {
1422
1423
let old_offset = index;
@@ -1496,12 +1497,8 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
1496
1497
// Ascii case, try to skip forward quickly.
1497
1498
// When the pointer is aligned, read 2 words of data per iteration
1498
1499
// 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 ( ) ;
1505
1502
while index < blocks_end {
1506
1503
unsafe {
1507
1504
let block = ptr. add ( index) as * const usize ;
You can’t perform that action at this time.
0 commit comments