File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,9 +38,8 @@ escaped_length(VALUE str)
3838static VALUE
3939optimized_escape_html (VALUE str )
4040{
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 ) {
4443 return str ;
4544 }
4645
@@ -62,8 +61,11 @@ optimized_escape_html(VALUE str)
6261 }
6362 }
6463
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+ }
6769 ALLOCV_END (vbuf );
6870 return escaped ;
6971}
You can’t perform that action at this time.
0 commit comments