Define object_buffer_limit from key_index_threshold Both mark the size up to which a linear key search is cheap: an object stays on the stack until then and, once spilled, looks up its keys in the hash index right away. Defining one from the other keeps them from drifting apart. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 086a1cb..06ad804 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp
@@ -1322,9 +1322,11 @@ } /// the number of members an object collects on the stack before it - /// switches to storing them directly; this is the size from which the - /// stored object looks up its keys in a hash table (key_index_threshold) - static constexpr std::size_t object_buffer_limit = 64; + /// switches to storing them directly; both collect_member() and a stored + /// object below key_index_threshold search their keys linearly, so the + /// object stays on the stack as long as a linear search is cheap, and a + /// spilled object looks up its keys in a hash table right away + static constexpr std::size_t object_buffer_limit = key_index_threshold; void reserve_members() {
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index cae779a..177a888 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp
@@ -17540,9 +17540,11 @@ } /// the number of members an object collects on the stack before it - /// switches to storing them directly; this is the size from which the - /// stored object looks up its keys in a hash table (key_index_threshold) - static constexpr std::size_t object_buffer_limit = 64; + /// switches to storing them directly; both collect_member() and a stored + /// object below key_index_threshold search their keys linearly, so the + /// object stays on the stack as long as a linear search is cheap, and a + /// spilled object looks up its keys in a hash table right away + static constexpr std::size_t object_buffer_limit = key_index_threshold; void reserve_members() {