mirror of
https://github.com/nlohmann/json.git
synced 2026-10-22 14:08:13 +00:00
An array of numbers was written one write_ubjson() call per element, each picking the marker of an integer by a ladder of range checks and writing it with a switch and several small sink writes. An array that starts with a number now encodes its runs of numbers straight into space reserved from the sink, as the CBOR and MessagePack writers do for integers. The marker and size of an integer come from a table indexed by the bit length of its magnitude, and its bytes are stored as one word, so that the code does not branch on their size; floats are stored the same way. Arrays that do not start with a number, and a single integer, keep the previous code. An unsigned integer UBJSON can only write as a high-precision number is left to write_ubjson(). Instructions per call (Linux, GCC 13, thousands), to_bjdata: 20000 integers 3278 -> 1086, 20000 floats 2193 -> 1000, canada 20829 -> 16805; to_ubjson: 20000 integers 3282 -> 1246, 20000 floats 2213 -> 1020. Signed-off-by: Niels Lohmann <mail@nlohmann.me>