File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -504,14 +504,11 @@ zend_result php_json_escape_string(
504
504
//}
505
505
//printf("\n");
506
506
507
- // TODO: problem if the first UTF-8 char comes before the first escape char
508
- // and getting this right+performant is hard, so for now we just don't shift.
507
+ int max_shift = 16 ;
508
+
509
509
int input_range_mask = _mm_movemask_epi8 (input_range );
510
510
if (input_range_mask != 0 ) {
511
- //int shift = __builtin_ctz(input_range_mask);
512
- //pos += shift;
513
- //len -= shift;
514
- break ;
511
+ max_shift = __builtin_ctz (input_range_mask );
515
512
}
516
513
517
514
#if 0
@@ -537,7 +534,13 @@ zend_result php_json_escape_string(
537
534
int mask = _mm_cvtsi128_si32 (result_individual_bytes );
538
535
#endif
539
536
if (mask != 0 ) {
540
- int shift = __builtin_clz (mask ) - 16 ;
537
+ if (max_shift < 16 ) {
538
+ int shift = __builtin_ctz (mask ); /* first offending character */
539
+ pos += MIN (max_shift , shift );
540
+ len -= MIN (max_shift , shift );
541
+ break ;
542
+ }
543
+ int shift = __builtin_clz (mask ) - 16 ; /* skips over everything */
541
544
do {
542
545
/* Note that we shift the input forward, so we have to shift the mask as well,
543
546
* beyond the to-be-escaped character */
@@ -557,6 +560,11 @@ zend_result php_json_escape_string(
557
560
558
561
pos += shift ;
559
562
} else {
563
+ if (max_shift < 16 ) {
564
+ pos += max_shift ;
565
+ len -= max_shift ;
566
+ break ;
567
+ }
560
568
pos += sizeof (__m128i );
561
569
}
562
570
You can’t perform that action at this time.
0 commit comments