File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed
portable/src/implementation Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -852,27 +852,22 @@ impl basic::imp::Utf8Validator for Utf8ValidatorImp {
852
852
return ;
853
853
}
854
854
}
855
- let len = input. len ( ) ;
856
- let mut idx: usize = 0 ;
857
- let iter_lim = len - ( len % SIMD_CHUNK_SIZE ) ;
858
- while idx < iter_lim {
859
- let input = SimdInput :: new ( & input[ idx..idx + SIMD_CHUNK_SIZE ] ) ;
855
+ // no incomplete data, check chunks
856
+ let mut chunks = input. chunks_exact ( SIMD_CHUNK_SIZE ) ;
857
+ for chunk in & mut chunks {
858
+ let input = SimdInput :: new ( chunk) ;
860
859
self . algorithm . check_utf8 ( & input) ;
861
- idx += SIMD_CHUNK_SIZE ;
862
860
}
863
- if idx < len {
864
- let to_copy = len - idx;
865
- self . incomplete_data [ ..to_copy] . copy_from_slice ( & input[ idx..idx + to_copy] ) ;
866
- self . incomplete_len = to_copy;
861
+ if !chunks. remainder ( ) . is_empty ( ) {
862
+ self . incomplete_data [ ..chunks. remainder ( ) . len ( ) ] . copy_from_slice ( chunks. remainder ( ) ) ;
863
+ self . incomplete_len = chunks. remainder ( ) . len ( ) ;
867
864
}
868
865
}
869
866
870
867
#[ inline]
871
868
fn finalize ( mut self ) -> core:: result:: Result < ( ) , basic:: Utf8Error > {
872
869
if self . incomplete_len != 0 {
873
- for i in & mut self . incomplete_data [ self . incomplete_len ..] {
874
- * i = 0 ;
875
- }
870
+ self . incomplete_data [ self . incomplete_len ..] . fill ( 0 ) ;
876
871
self . update_from_incomplete_data ( ) ;
877
872
}
878
873
self . algorithm . check_incomplete_pending ( ) ;
You can’t perform that action at this time.
0 commit comments