From fce5a54722c3e5ceb51453553eaf101cd2b8c0a5 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 23 Oct 2026 12:07:53 +0200 Subject: [PATCH] 2.5.7: force-inline detail::parse_array_index (#5891) Moving parse_array_index out of json_pointer stopped clang from inlining it into the pointer resolution (JsonPointerAt/citm_catalog +17%, JsonPointerAt/twitter +8%); JSON_HEDLEY_ALWAYS_INLINE restores the baseline. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/json_pointer.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 0c930c75a..4560714ab 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -70,9 +70,11 @@ enum class array_index_status @note this function never throws; json_pointer::array_index(), the callers that must not throw, and the json_view pointer resolution build on it instead of each re-implementing the RFC 6901 digit rules and the range check +@note force-inlined: as a free function template it is no longer inlined into + the pointer resolution, which makes JsonPointerAt up to 17% slower (#5891) */ template -array_index_status parse_array_index(const StringType& s, SizeType& idx) noexcept +JSON_HEDLEY_ALWAYS_INLINE array_index_status parse_array_index(const StringType& s, SizeType& idx) noexcept { // error condition (cf. RFC 6901, Sect. 4) if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))