Skip to content

Conversation

@noteflakes
Copy link

This is a port of the change I submitted in ruby/erb#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.

@hsbt
Copy link
Member

hsbt commented Oct 13, 2025

Thanks. I will look test failure of mingw platform. It may be caused with ruby/setup-ruby#818

@nobu nobu force-pushed the optimized_escape_html branch from 8834387 to 6a77d43 Compare November 26, 2025 08:13
with no escapable character

- Perform buffer allocation on first instance of
  escapable character.
- Instead of copying characters one at a time,
  copy unescaped segments using `memcpy`.
@ioquatix ioquatix force-pushed the optimized_escape_html branch from 6a77d43 to 469a45e Compare December 9, 2025 02:39
const char *segment_start = cstr;
char *dest = NULL;
while (cstr < end) {
const unsigned char c = *cstr++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this line confusing, since it means on line 60 we need to subtract by 1 to undo the increment. Can we move the increment to the end of the loop?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants