mirror of
https://github.com/nlohmann/json.git
synced 2026-10-31 18:05:44 +00:00
json::accept() parses through json_sax_acceptor, which ignores the values of strings and object keys, but the lexer still copied every string token into its token buffer. That copy was 18 % of the instructions of json::accept() on twitter.json (x86, GCC 16). The lexer's flag for accept(), renamed from discard_number_values to discard_values, now also selects a second instantiation of scan_string() that performs the same checks (escapes, surrogates, UTF-8, control characters, with the same error messages) without writing to the token buffer. scan() chooses the instantiation once per string: a run-time check inside the string loop made number-heavy files up to 3 % slower on Apple M1. json::accept() over 19 files, time after/before (geomean): 0.876 on x86 with GCC 16.2, 0.884 with Clang 23, 0.932 on Apple M1; up to 0.74 on single files; files with few strings (canada, mesh, numbers) unchanged. Signed-off-by: Niels Lohmann <mail@nlohmann.me>