aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-11-03 23:34:09 -0700
committergit <svn-admin@ruby-lang.org>2022-11-04 07:07:24 +0000
commitccf32a5ca4ce29f9019cf8bae9f3c0f69e27bd22 (patch)
tree4443a30c15e9b6b1e2e68ce67c52660286cf6cff
parent20efeaddbe246f3b2eaee4f17f54a814777176a8 (diff)
downloadruby-ccf32a5ca4ce29f9019cf8bae9f3c0f69e27bd22.tar.gz
[ruby/erb] Do not allocate a new String if not needed
[Feature #19102]https://github.com/ruby/erb/commit/ecebf8075c
-rw-r--r--ext/erb/erb.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/ext/erb/erb.c b/ext/erb/erb.c
index 9376fa5dcb..4adab8ad33 100644
--- a/ext/erb/erb.c
+++ b/ext/erb/erb.c
@@ -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)
{