1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/erb] Do not allocate a new String if not needed

[Feature #19102]https://github.com/ruby/erb/commit/ecebf8075c
This commit is contained in:
Takashi Kokubun 2022-11-03 23:34:09 -07:00 committed by git
parent 20efeaddbe
commit ccf32a5ca4

View file

@ -55,18 +55,18 @@ optimized_escape_html(VALUE str)
}
}
VALUE escaped;
VALUE escaped = str;
if (RSTRING_LEN(str) < (dest - buf)) {
escaped = rb_str_new(buf, dest - buf);
preserve_original_state(str, escaped);
}
else {
escaped = rb_str_dup(str);
}
ALLOCV_END(vbuf);
return escaped;
}
// ERB::Util.html_escape is different from CGI.escapeHTML in the following two parts:
// * ERB::Util.html_escape converts an argument with #to_s first (only if it's not T_STRING)
// * ERB::Util.html_escape does not allocate a new string when nothing needs to be escaped
static VALUE
erb_escape_html(VALUE self, VALUE str)
{