mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 03:30:31 +00:00
Long runs of string bytes are scanned 16 at a time with NEON (AArch64, with GCC and Clang) and SSE2 (x86-64): both belong to the baseline instruction sets. A signed compare with 0x20 finds control characters and non-ASCII bytes at once. Keys keep 16 table checks before the vector loop (their lengths repeat from record to record, so the branches predict well); string values have 8, as their lengths vary more. Non-ASCII text is validated 16 bytes at a time with the "lookup4" check of simdjson (J. Keiser and D. Lemire, "Validating UTF-8 In Less Than One Instruction Per Byte", 2021): with NEON, and on x86-64 with SSSE3 if JSON_VIEW_USE_SSSE3 is defined (SSSE3 is not part of x86-64, and the code must not depend on the flags of a translation unit). JSON_VIEW_NO_SIMD selects the portable code. The vector code sits in detail/view/simd.hpp; the same input is accepted either way. json_document::parse, best of 7 runs in separate processes (M1 Max): poet.json (CJK text) -72%, random.json -25%, twitter.json -22%, gsoc-2018.json -20%, semanticscholar -19%, github_events -11%, apache_builds -9.5%, canada/citm -5/-6%; lottie +4%, tree-pretty +2.5%. Tests: every two-byte sequence and three- and four-byte sequences with continuation bytes at the edges of their ranges, at every offset around the vector blocks of keys and values, cut short, and long runs of text with a damaged byte, against json::accept and json::parse. CMake builds the parser tests again with JSON_VIEW_NO_SIMD, and on x86-64 with JSON_VIEW_USE_SSSE3 and -mssse3; the macros are documented. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
27 lines
812 B
C++
27 lines
812 B
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
|
|
|
|
// undefine the macros of detail/view/macro_scope.hpp (at the end of json_view.hpp)
|
|
|
|
#undef NLOHMANN_VIEW_HAS_CPP_17
|
|
#undef NLOHMANN_VIEW_LIKELY
|
|
#undef NLOHMANN_VIEW_UNLIKELY
|
|
#undef NLOHMANN_VIEW_ALWAYS_INLINE
|
|
#undef NLOHMANN_VIEW_NOINLINE
|
|
#undef NLOHMANN_VIEW_NODISCARD
|
|
#undef NLOHMANN_VIEW_THROW
|
|
#undef NLOHMANN_VIEW_LITTLE_ENDIAN
|
|
#undef NLOHMANN_VIEW_REPEAT16
|
|
#undef NLOHMANN_VIEW_NEON
|
|
#undef NLOHMANN_VIEW_SSE2
|
|
#undef NLOHMANN_VIEW_SSSE3
|
|
#undef NLOHMANN_VIEW_VECTOR
|
|
#undef NLOHMANN_VIEW_VECTOR_UTF8
|