@@ -605,6 +605,27 @@ impl<'de> Deserializer<'de> {
605605
606606/// architecture dependant `find_structural_bits`
607607impl Deserializer < ' _ > {
608+ #[ cfg_attr( not( feature = "no-inline" ) , inline) ]
609+ /// Native fallback that pre-validates UTF-8 before finding structural bits,
610+ /// since the native `ChunkedUtf8ValidatorImp` is a no-op.
611+ #[ cfg( all(
612+ feature = "runtime-detection" ,
613+ any( target_arch = "x86_64" , target_arch = "x86" ) ,
614+ not( feature = "portable" ) ,
615+ ) ) ]
616+ pub ( crate ) unsafe fn find_structural_bits_native (
617+ input : & [ u8 ] ,
618+ structural_indexes : & mut Vec < u32 > ,
619+ ) -> std:: result:: Result < ( ) , ErrorType > {
620+ match core:: str:: from_utf8 ( input) {
621+ Ok ( _) => ( ) ,
622+ Err ( _) => return Err ( ErrorType :: InvalidUtf8 ) ,
623+ } ;
624+ unsafe {
625+ Self :: _find_structural_bits :: < impls:: native:: SimdInput > ( input, structural_indexes)
626+ }
627+ }
628+
608629 #[ cfg_attr( not( feature = "no-inline" ) , inline) ]
609630 #[ cfg( all(
610631 feature = "runtime-detection" ,
@@ -629,7 +650,7 @@ impl Deserializer<'_> {
629650 #[ cfg( feature = "portable" ) ]
630651 let r = Deserializer :: _find_structural_bits :: < impls:: portable:: SimdInput > ;
631652 #[ cfg( not( feature = "portable" ) ) ]
632- let r = Deserializer :: _find_structural_bits :: < impls :: native :: SimdInput > ;
653+ let r = Deserializer :: find_structural_bits_native ;
633654 r
634655 }
635656 }
0 commit comments