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:
parent
20efeaddbe
commit
ccf32a5ca4
1 changed files with 4 additions and 4 deletions
|
@ -55,18 +55,18 @@ optimized_escape_html(VALUE str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE escaped;
|
VALUE escaped = str;
|
||||||
if (RSTRING_LEN(str) < (dest - buf)) {
|
if (RSTRING_LEN(str) < (dest - buf)) {
|
||||||
escaped = rb_str_new(buf, dest - buf);
|
escaped = rb_str_new(buf, dest - buf);
|
||||||
preserve_original_state(str, escaped);
|
preserve_original_state(str, escaped);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
escaped = rb_str_dup(str);
|
|
||||||
}
|
|
||||||
ALLOCV_END(vbuf);
|
ALLOCV_END(vbuf);
|
||||||
return escaped;
|
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
|
static VALUE
|
||||||
erb_escape_html(VALUE self, VALUE str)
|
erb_escape_html(VALUE self, VALUE str)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue