@@ -68,21 +68,18 @@ cfg_match! {
6868
6969 const CHUNK_SIZE : usize = 16 ;
7070
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 >( ) ;
7472
7573 // This variable keeps track of where we should start decoding a
7674 // chunk. If a multi-byte character spans across chunk boundaries,
7775 // we need to skip that part in the next chunk because we already
7876 // handled it.
7977 let mut intra_chunk_offset = 0 ;
8078
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( ) {
8380 // We don't know if the pointer is aligned to 16 bytes, so we
8481 // 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 ) } ;
8683
8784 // For character in the chunk, see if its byte value is < 0, which
8885 // indicates that it's part of a UTF-8 char.
@@ -123,7 +120,7 @@ cfg_match! {
123120 }
124121
125122 // 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;
127124 if tail_start < src. len( ) {
128125 analyze_source_file_generic(
129126 & src[ tail_start..] ,
0 commit comments