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 {
852852 return ;
853853 }
854854 }
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) ;
860859 self . algorithm . check_utf8 ( & input) ;
861- idx += SIMD_CHUNK_SIZE ;
862860 }
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 ( ) ;
867864 }
868865 }
869866
870867 #[ inline]
871868 fn finalize ( mut self ) -> core:: result:: Result < ( ) , basic:: Utf8Error > {
872869 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 ) ;
876871 self . update_from_incomplete_data ( ) ;
877872 }
878873 self . algorithm . check_incomplete_pending ( ) ;
You can’t perform that action at this time.
0 commit comments