diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2022-05-08 14:55:57 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2022-05-11 23:51:48 -0400 |
commit | fc32d4c9d3235157725a4eb7faccd4933ed7ea9f (patch) | |
tree | 4a65db11fbc2302df59794854e06cdefba9c3a85 /src/buffer.c | |
parent | d22e88b7d9fdec286754f321b53b7cdd81d117c4 (diff) | |
download | lighttpd-git-fc32d4c9d3235157725a4eb7faccd4933ed7ea9f.tar.gz |
[core] buffer_append_string_c_escaped ASCII optim
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/buffer.c b/src/buffer.c index a7ebf956..507d7679 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -664,8 +664,9 @@ void buffer_append_string_c_escaped(buffer * const restrict b, const char * cons /* count to-be-encoded-characters */ for (ds = (unsigned char *)s, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) { - if ((*ds < 0x20) /* control character */ - || (*ds >= 0x7f)) { /* DEL + non-ASCII characters */ + if (__builtin_expect( (*ds >= ' ' && *ds <= '~'), 1)) + d_len++; + else { /* CTLs or non-ASCII characters */ switch (*ds) { case '\t': case '\r': @@ -676,8 +677,6 @@ void buffer_append_string_c_escaped(buffer * const restrict b, const char * cons d_len += 4; /* \xCC */ break; } - } else { - d_len++; } } @@ -689,8 +688,9 @@ void buffer_append_string_c_escaped(buffer * const restrict b, const char * cons } for (ds = (unsigned char *)s, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) { - if ((*ds < 0x20) /* control character */ - || (*ds >= 0x7f)) { /* DEL + non-ASCII characters */ + if (__builtin_expect( (*ds >= ' ' && *ds <= '~'), 1)) + d[d_len++] = *ds; + else { /* CTLs or non-ASCII characters */ d[d_len++] = '\\'; switch (*ds) { case '\t': @@ -704,12 +704,10 @@ void buffer_append_string_c_escaped(buffer * const restrict b, const char * cons break; default: d[d_len++] = 'x'; - d[d_len++] = hex_chars_lc[((*ds) >> 4) & 0x0F]; + d[d_len++] = hex_chars_lc[(*ds) >> 4]; d[d_len++] = hex_chars_lc[(*ds) & 0x0F]; break; } - } else { - d[d_len++] = *ds; } } } |