mirror of
https://github.com/nlohmann/json.git
synced 2026-10-22 14:08:13 +00:00
A string or object key took a string_t constructed for the UTF-8 error handler, a call of the (out of line) sanitize_utf8_for_write() that returns the string unchanged for the default handler, a call that builds the head from a range-checked length and writes it with a std::array and a sink call of its own, and a sink write for the characters, which copied it with a call of memcpy() through a stub with its own dispatch on the length. With the default error handler (keep) and a string of up to 254 characters, the head and the characters are now written into space reserved from the sink in one go. Longer strings and the other handlers take the previous code. The sinks copy up to 32 characters with fixed-size loads and stores - two possibly overlapping 16, 8 or 4 byte copies, or the first, middle and last character of a string of 1 to 3 - instead of calling memcpy(); nothing outside of the source or destination range is touched. Instructions per call (Linux, GCC 13, thousands), to_msgpack: twitter 4414 -> 3383, 20000 small objects 23895 -> 18342, citm_catalog 8575 -> 7031; to_cbor: 20000 small objects 20695 -> 17182, twitter 3842 -> 3204. Signed-off-by: Niels Lohmann <mail@nlohmann.me>