Skip to content

Commit

Permalink
Do not allocate a new String if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Nov 4, 2022
1 parent 0ca0319 commit 24a4af5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ext/erb/erb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 24a4af5

Please sign in to comment.