Address review: drop unneeded backslash-escapes and duplicate scan loop

'"' does not need escaping in a char literal, unlike in a string literal.
find_ascii_copyable_run() also duplicated the byte-at-a-time search that
already exists as the loop's own scalar tail; break into it instead of
re-deriving the offset in a second, near-identical loop.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-09-10 18:02:56 +02:00
committed by GitHub
parent 6ddd00edcb
commit 8c22567a49
3 changed files with 24 additions and 36 deletions
@@ -101,7 +101,7 @@ inline std::size_t find_string_special(const unsigned char* data, std::size_t n)
// \u007f under ensure_ascii).
inline bool is_ascii_copyable(unsigned char c) noexcept
{
return c >= 0x20u && c < 0x7Fu && c != '\"' && c != '\\';
return c >= 0x20u && c < 0x7Fu && c != '"' && c != '\\';
}
// return the index of the first byte in [data, data+n) that is NOT
@@ -126,13 +126,7 @@ inline std::size_t find_ascii_copyable_run(const unsigned char* data, std::size_
| (v & high); // >= 0x80
if (stop != 0)
{
for (std::size_t j = 0; j < 8; ++j)
{
if (!is_ascii_copyable(data[i + j]))
{
return i + j;
}
}
break;
}
}
for (; i < n; ++i)