Most strings in real documents are object keys and short values. For those, dump_escaped() scanned the bytes, called memcpy with a length known only at run time, and the surrounding quote, colon and space were three more bounds-checked writes. A string of up to 16 printable ASCII characters (no quote, backslash or DEL) is now read with two overlapping loads, checked with one SWAR test per word, and written together with its quotes and the colon with two overlapping stores. Anything else, and a write buffer without room, takes the general path unchanged. Little-endian targets only; others keep the general path. dump_scalar() held the code of every scalar type and saved and restored all callee-saved registers on every call. It only dispatches now, and the string, integer, float and binary writers are functions of their own, so each pays only for what it uses (the string path keeps the check for long strings in front of any attempt, which keeps documents of long strings neutral). Apple M1, Apple clang, retired instructions per dump(), on top of the printable-ASCII table of #5878: citm_catalog 7.54M -> 5.96M (-21 %) twitter 4.87M -> 4.40M (-10 %) jeopardy 603M -> 501M (-17 %) logs 8.65M -> 8.17M (-5 %) a 139-byte object 3497 -> 2997 (-14 %) signed_ints -4 %, canada -3 % Linux x86-64 (callgrind), the whole series against develop, gcc 13 / clang 18: citm_catalog -16 % / -19 % (compact), twitter -22 % / -24 %. Documents of long strings (paths, latin and CJK text) are within 1 %. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
// __ _____ _____ _____
|
|
// __| | __| | | | JSON for Modern C++
|
|
// | | |__ | | | | | | version 3.12.0
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
//
|
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
// clean up
|
|
#undef JSON_ASSERT
|
|
#undef JSON_INTERNAL_CATCH
|
|
#undef JSON_THROW
|
|
#undef JSON_PRIVATE_UNLESS_TESTED
|
|
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
|
#undef NLOHMANN_BASIC_JSON_TPL
|
|
#undef JSON_EXPLICIT
|
|
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
|
|
#undef JSON_INLINE_VARIABLE
|
|
#undef JSON_NO_UNIQUE_ADDRESS
|
|
#undef JSON_DISABLE_ENUM_SERIALIZATION
|
|
#undef JSON_DISABLE_TUPLE_REFERENCE_CONVERSION
|
|
#undef JSON_UNLOCKED_FILE_IO
|
|
#undef JSON_DTOA_SSE2
|
|
#undef JSON_DTOA_NEON
|
|
#undef JSON_LITTLE_ENDIAN_TARGET
|
|
#undef JSON_BIG_ENDIAN_TARGET
|
|
#undef JSON_SCAN_NEON
|
|
#undef JSON_SCAN_SSE2
|
|
#undef JSON_SCAN_SSSE3
|
|
#undef JSON_SCAN_SSSE3_DISPATCH
|
|
#undef JSON_SCAN_SSSE3_TARGET
|
|
#undef JSON_SCAN_VECTOR
|
|
#undef JSON_SCAN_VECTOR_UTF8
|
|
#undef JSON_DUMP_SHORT_STRINGS
|
|
|
|
#ifndef JSON_TEST_KEEP_MACROS
|
|
#undef JSON_CATCH
|
|
#undef JSON_TRY
|
|
#undef JSON_HAS_CPP_11
|
|
#undef JSON_HAS_CPP_14
|
|
#undef JSON_HAS_CPP_17
|
|
#undef JSON_HAS_CPP_20
|
|
#undef JSON_HAS_CPP_23
|
|
#undef JSON_HAS_CPP_26
|
|
#undef JSON_HAS_FILESYSTEM
|
|
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
#undef JSON_HAS_THREE_WAY_COMPARISON
|
|
#undef JSON_HAS_RANGES
|
|
#undef JSON_HAS_RANGE_VIEW_CONVERSION
|
|
#undef JSON_HAS_STD_FORMAT
|
|
#undef JSON_HAS_STATIC_RTTI
|
|
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
|
|
#undef JSON_BRACE_INIT_COPY_SEMANTICS
|
|
#undef JSON_PRECISE_STREAM_POSITION
|
|
#undef JSON_STRICT_NUL_HANDLING
|
|
#undef JSON_STRICT_BINARY_UTF8
|
|
#undef JSON_DELETE_DEPRECATED_FUNCTIONS
|
|
#undef JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS
|
|
#undef JSON_DISABLE_STREAM_BULK_SCAN
|
|
#undef JSON_DISABLE_UNLOCKED_FILE_IO
|
|
#endif
|
|
|
|
#include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
|