Faster JSON string serialisation (bug#80529)

* src/json.c (json_out_string):
Optimise for runs of non-special ASCII chars.

This seems to be a a substantial performance gain for long strings but a
smaller regression for short strings (up to 6 chars or thereabouts,
depending on cpu, compiler, and/or C library).  Still likely worth it.

Suggested by Pavel <cyberkm@gmail.com>.
This commit is contained in:
Mattias Engdegård 2026-03-03 17:13:36 +01:00
parent 72a1bda759
commit dfa4a0e5a2

View file

@ -332,13 +332,17 @@ json_out_string (json_out_t *jo, Lisp_Object str, int skip)
p += skip;
while (p < end)
{
unsigned char c = *p;
if (json_plain_char[c])
unsigned char *run = p;
while (p < end && json_plain_char[*p])
p++;
if (p > run)
{
json_out_byte (jo, c);
p++;
json_out_str (jo, (const char *)run, p - run);
continue;
}
else if (c > 0x7f)
unsigned char c = *p;
if (c > 0x7f)
{
if (STRING_MULTIBYTE (str))
{