Improve performance of UTF-8 validation (#3675)

jvp_utf8_next() had a fast path for ASCII, but it is not inlined into
its callers, so every byte of a string cost a function call.

Move the end check and the ASCII case into a static inline function in
jv_unicode.h and keep the rest out of line. This speeds up parsing of
string-heavy input by up to 1.17x and string functions such as length,
explode and @html, with the same output for every input.
This commit is contained in:
Michiel van Slobbe authored and GitHub committed 2026-10-20 22:03:29 +09:00
1 parent 633ae6058a
commit 852c4d6096
4 files changed
+30 -12

No files matched your search

+5
View File
@@ -84,6 +84,11 @@ null
"Zm/Ds2Jhcgo="
"foóbar\n"
# Invalid UTF-8 next to ASCII runs is still replaced
map(@base64d)
["YWJjZGVmZ2hpav9rbG1ub3A=", "YWJjZGVmZ2hpasOpa2xtbm9w5pel", "/2FiY2RlZmdoaWo=", "YWJjZGVmZ2hpauaX", "YWJjZGVmZ2hpau2ggHh5eg=="]
["abcdefghij�klmnop","abcdefghijéklmnop日","�abcdefghij","abcdefghij�","abcdefghij�xyz"]
@uri
"\u03bc"
"%CE%BC"