@@ -68,21 +68,18 @@ cfg_match! {
68
68
69
69
const CHUNK_SIZE : usize = 16 ;
70
70
71
- let src_bytes = src. as_bytes( ) ;
72
-
73
- let chunk_count = src. len( ) / CHUNK_SIZE ;
71
+ let ( chunks, tail) = src. as_bytes( ) . as_chunks:: <CHUNK_SIZE >( ) ;
74
72
75
73
// This variable keeps track of where we should start decoding a
76
74
// chunk. If a multi-byte character spans across chunk boundaries,
77
75
// we need to skip that part in the next chunk because we already
78
76
// handled it.
79
77
let mut intra_chunk_offset = 0 ;
80
78
81
- for chunk_index in 0 ..chunk_count {
82
- let ptr = src_bytes. as_ptr( ) as * const __m128i;
79
+ for ( chunk_index, chunk) in chunks. iter( ) . enumerate( ) {
83
80
// We don't know if the pointer is aligned to 16 bytes, so we
84
81
// use `loadu`, which supports unaligned loading.
85
- let chunk = unsafe { _mm_loadu_si128( ptr . add ( chunk_index ) ) } ;
82
+ let chunk = unsafe { _mm_loadu_si128( chunk . as_ptr ( ) as * const __m128i ) } ;
86
83
87
84
// For character in the chunk, see if its byte value is < 0, which
88
85
// indicates that it's part of a UTF-8 char.
@@ -123,7 +120,7 @@ cfg_match! {
123
120
}
124
121
125
122
// There might still be a tail left to analyze
126
- let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset;
123
+ let tail_start = src . len ( ) - tail . len ( ) + intra_chunk_offset;
127
124
if tail_start < src. len( ) {
128
125
analyze_source_file_generic(
129
126
& src[ tail_start..] ,
0 commit comments