@@ -12,7 +12,7 @@ use faststr::FastStr;
1212use serde:: de:: { self , Expected , Unexpected } ;
1313use sonic_number:: { parse_number, ParserNumber } ;
1414#[ cfg( all( target_feature = "neon" , target_arch = "aarch64" ) ) ]
15- use sonic_simd:: bits:: NeonBits ;
15+ // use sonic_simd::bits::NeonBits; // not used with unified u32 path
1616use sonic_simd:: { i8x32, m8x32, u8x32, u8x64, Mask , Simd } ;
1717
1818use crate :: {
@@ -900,36 +900,29 @@ where
900900 & mut self ,
901901 buf : & ' own mut Vec < u8 > ,
902902 ) -> Result < ParsedSlice < ' de , ' own > > {
903- #[ cfg( all( target_feature = "neon" , target_arch = "aarch64" ) ) ]
904- let mut block: StringBlock < NeonBits > ;
905- #[ cfg( not( all( target_feature = "neon" , target_arch = "aarch64" ) ) ) ]
906- let mut block: StringBlock < u32 > ;
907-
908903 self . parse_escaped_char ( buf) ?;
909904
910- while let Some ( chunk) = self . read . peek_n ( StringBlock :: LANES ) {
911- buf. reserve ( StringBlock :: LANES ) ;
912- let v = unsafe { load ( chunk. as_ptr ( ) ) } ;
913- block = StringBlock :: new ( & v) ;
914-
905+ while let Some ( chunk) = self . read . peek_n ( crate :: util:: string:: STRING_BLOCK_LANES ) {
906+ buf. reserve ( crate :: util:: string:: STRING_BLOCK_LANES ) ;
907+ let v = crate :: util:: string:: load_v ( chunk. as_ptr ( ) ) ;
908+ let block = crate :: util:: string:: build_block ( & v) ;
909+ // write the chunk to buf, we will set new_len later
910+ let dst_chunk = from_raw_parts_mut (
911+ buf. as_mut_ptr ( ) . add ( buf. len ( ) ) ,
912+ crate :: util:: string:: STRING_BLOCK_LANES ,
913+ ) ;
914+ v. write_to_slice_unaligned_unchecked ( dst_chunk) ;
915915 if block. has_unescaped ( ) {
916916 self . read . eat ( block. unescaped_index ( ) ) ;
917917 return perr ! ( self , ControlCharacterWhileParsingString ) ;
918918 }
919-
920- // write the chunk to buf, we will set new_len later
921- let chunk = from_raw_parts_mut ( buf. as_mut_ptr ( ) . add ( buf. len ( ) ) , StringBlock :: LANES ) ;
922- v. write_to_slice_unaligned_unchecked ( chunk) ;
923-
924919 if block. has_quote_first ( ) {
925920 let cnt = block. quote_index ( ) ;
926921 buf. set_len ( buf. len ( ) + cnt) ;
927-
928922 // skip the right quote
929923 self . read . eat ( cnt + 1 ) ;
930924 return Ok ( ParsedSlice :: Copied ( buf) ) ;
931925 }
932-
933926 if block. has_backslash ( ) {
934927 // TODO: loop unrooling here
935928 let cnt = block. bs_index ( ) ;
@@ -938,9 +931,10 @@ where
938931 buf. set_len ( buf. len ( ) + cnt) ;
939932 self . parse_escaped_char ( buf) ?;
940933 } else {
941- buf. set_len ( buf. len ( ) + StringBlock :: LANES ) ;
942- self . read . eat ( StringBlock :: LANES ) ;
934+ buf. set_len ( buf. len ( ) + crate :: util :: string :: STRING_BLOCK_LANES ) ;
935+ self . read . eat ( crate :: util :: string :: STRING_BLOCK_LANES ) ;
943936 }
937+ continue ;
944938 }
945939
946940 // scalar codes
@@ -974,27 +968,21 @@ where
974968 ) -> Result < ParsedSlice < ' de , ' own > > {
975969 // now reader is start after `"`, so we can directly skipstring
976970 let start = self . read . index ( ) ;
977- #[ cfg( all( target_feature = "neon" , target_arch = "aarch64" ) ) ]
978- let mut block: StringBlock < NeonBits > ;
979- #[ cfg( not( all( target_feature = "neon" , target_arch = "aarch64" ) ) ) ]
980- let mut block: StringBlock < u32 > ;
981-
982- while let Some ( chunk) = self . read . peek_n ( StringBlock :: LANES ) {
983- let v = unsafe { load ( chunk. as_ptr ( ) ) } ;
984- block = StringBlock :: new ( & v) ;
971+ // use arch-aware block builder to keep lanes consistent
985972
973+ while let Some ( chunk) = self . read . peek_n ( crate :: util:: string:: STRING_BLOCK_LANES ) {
974+ let v = crate :: util:: string:: load_v ( chunk. as_ptr ( ) ) ;
975+ let block = crate :: util:: string:: build_block ( & v) ;
986976 if block. has_quote_first ( ) {
987977 let cnt = block. quote_index ( ) ;
988978 self . read . eat ( cnt + 1 ) ;
989979 let slice = self . read . slice_unchecked ( start, self . read . index ( ) - 1 ) ;
990980 return Ok ( ParsedSlice :: Borrowed { slice, buf } ) ;
991981 }
992-
993982 if block. has_unescaped ( ) {
994983 self . read . eat ( block. unescaped_index ( ) ) ;
995984 return perr ! ( self , ControlCharacterWhileParsingString ) ;
996985 }
997-
998986 if block. has_backslash ( ) {
999987 let cnt = block. bs_index ( ) ;
1000988 // skip the backslash
@@ -1006,8 +994,7 @@ where
1006994
1007995 return unsafe { self . parse_string_escaped ( buf) } ;
1008996 }
1009-
1010- self . read . eat ( StringBlock :: LANES ) ;
997+ self . read . eat ( crate :: util:: string:: STRING_BLOCK_LANES ) ;
1011998 continue ;
1012999 }
10131000
0 commit comments