File tree Expand file tree Collapse file tree 2 files changed +460
-483
lines changed Expand file tree Collapse file tree 2 files changed +460
-483
lines changed Original file line number Diff line number Diff line change @@ -127,12 +127,19 @@ pub fn escape<S: AsRef<str>>(input: S) -> String {
127
127
result. push ( b'"' ) ;
128
128
let s = input. as_ref ( ) ;
129
129
let bytes = s. as_bytes ( ) ;
130
+ let len = bytes. len ( ) ;
130
131
// Runtime CPU feature detection for x86_64
131
- if is_x86_feature_detected ! ( "avx512f" ) && is_x86_feature_detected ! ( "avx512bw" ) {
132
+ if is_x86_feature_detected ! ( "avx512f" )
133
+ && is_x86_feature_detected ! ( "avx512bw" )
134
+ && len >= x86:: LOOP_SIZE_AVX512
135
+ {
132
136
unsafe { x86:: escape_avx512 ( bytes, & mut result) }
133
- } else if is_x86_feature_detected ! ( "avx2" ) {
137
+ } else if is_x86_feature_detected ! ( "avx2" ) && len >= x86 :: LOOP_SIZE_AVX2 {
134
138
unsafe { x86:: escape_avx2 ( bytes, & mut result) }
135
- } else if is_x86_feature_detected ! ( "sse2" ) {
139
+ } else if is_x86_feature_detected ! ( "sse2" )
140
+ && /* if len < 128, no need to use simd */
141
+ len >= x86:: LOOP_SIZE_AVX2
142
+ {
136
143
unsafe { x86:: escape_sse2 ( bytes, & mut result) }
137
144
} else {
138
145
escape_inner ( bytes, & mut result) ;
You can’t perform that action at this time.
0 commit comments