json_view: keep GCC from cloning scan_string_vector

With the builder of accept() in the same translation unit, GCC 16's
interprocedural constant propagation cloned scan_string_vector without its
plain argument (always string_plain()). The parse loop of
json_document::parse() then called the clone, and GCC generated different
code for the whole loop: 0.7-1.2 % more instructions (twitter, citm_catalog,
instruments, tree-pretty, canada) and up to +13 % time on citm_catalog.
NLOHMANN_VIEW_NOCLONE (GCC only) keeps the function as written; the
instruction counts of parse() are then those of develop again.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-31 18:03:40 +01:00
1 parent 56c6eaf2ad
commit 6548a65b46
5 files changed
+31 -5

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@
#endif
// the view's own macros do not leak
#if defined(NLOHMANN_VIEW_LIKELY) || defined(NLOHMANN_VIEW_UNLIKELY) || defined(NLOHMANN_VIEW_ALWAYS_INLINE) || defined(NLOHMANN_VIEW_NOINLINE) \
#if defined(NLOHMANN_VIEW_LIKELY) || defined(NLOHMANN_VIEW_UNLIKELY) || defined(NLOHMANN_VIEW_ALWAYS_INLINE) || defined(NLOHMANN_VIEW_NOINLINE) || defined(NLOHMANN_VIEW_NOCLONE) \
|| defined(NLOHMANN_VIEW_NODISCARD) || defined(NLOHMANN_VIEW_THROW) || defined(NLOHMANN_VIEW_HAS_CPP_17) || defined(NLOHMANN_VIEW_LITTLE_ENDIAN) \
|| defined(NLOHMANN_VIEW_REPEAT16)
#error "json_view.hpp leaks a macro"