File tree 1 file changed +7
-5
lines changed 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,8 @@ escaped_length(VALUE str)
38
38
static VALUE
39
39
optimized_escape_html (VALUE str )
40
40
{
41
- // Optimize the most common, no-escape case with strpbrk(3). Not using it after
42
- // this because calling a C function many times could be slower for some cases.
43
- if (strpbrk (RSTRING_PTR (str ), "'&\"<>" ) == NULL ) {
41
+ // Use strpbrk to optimize the no-escape case when str is long enough for SIMD.
42
+ if (RSTRING_LEN (str ) >= 16 && strpbrk (RSTRING_PTR (str ), "'&\"<>" ) == NULL ) {
44
43
return str ;
45
44
}
46
45
@@ -62,8 +61,11 @@ optimized_escape_html(VALUE str)
62
61
}
63
62
}
64
63
65
- VALUE escaped = rb_str_new (buf , dest - buf );
66
- preserve_original_state (str , escaped );
64
+ VALUE escaped = str ;
65
+ if (RSTRING_LEN (str ) < (dest - buf )) {
66
+ escaped = rb_str_new (buf , dest - buf );
67
+ preserve_original_state (str , escaped );
68
+ }
67
69
ALLOCV_END (vbuf );
68
70
return escaped ;
69
71
}
You can’t perform that action at this time.
0 commit comments