cgi icon indicating copy to clipboard operation
cgi copied to clipboard

escape_html: Avoid buffer allocation for strings with no escapable character

Open noteflakes opened this issue 2 months ago • 1 comments

This is a port of the change I submitted in https://github.com/ruby/erb/pull/87.

  • Perform buffer allocation on first instance of escapable character.
  • Instead of copying characters one at a time, copy unescaped segments using memcpy.

Note: the cgi implementation differs from the erb implementation in that it always creates a new string (using rb_str_dup), even for strings without any escapable characters, while the erb implementation will return the input string unchanged.

noteflakes avatar Oct 13 '25 10:10 noteflakes

Thanks. I will look test failure of mingw platform. It may be caused with https://github.com/ruby/setup-ruby/issues/818

hsbt avatar Oct 13 '25 23:10 hsbt