Skip to content

Commit ecebf80

Browse files
committed
Do not allocate a new String if not needed
[Feature #19102]
1 parent 38c6e18 commit ecebf80

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ext/erb/erb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ optimized_escape_html(VALUE str)
5555
}
5656
}
5757

58-
VALUE escaped;
58+
VALUE escaped = str;
5959
if (RSTRING_LEN(str) < (dest - buf)) {
6060
escaped = rb_str_new(buf, dest - buf);
6161
preserve_original_state(str, escaped);
6262
}
63-
else {
64-
escaped = rb_str_dup(str);
65-
}
6663
ALLOCV_END(vbuf);
6764
return escaped;
6865
}
6966

67+
// ERB::Util.html_escape is different from CGI.escapeHTML in the following two parts:
68+
// * ERB::Util.html_escape converts an argument with #to_s first (only if it's not T_STRING)
69+
// * ERB::Util.html_escape does not allocate a new string when nothing needs to be escaped
7070
static VALUE
7171
erb_escape_html(VALUE self, VALUE str)
7272
{

0 commit comments

Comments
 (0)