mirror of
https://github.com/nlohmann/json.git
synced 2026-10-05 22:20:30 +00:00
Only track the target key order in diff() for insertion-ordered objects
common_keys_target_order and new_keys_form_suffix are only read when object_t keeps its members in insertion order; skip building them otherwise. Addresses review comment by @gregmarr. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -6150,12 +6150,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
// the same time, determine whether every added key comes
|
// the same time, determine whether every added key comes
|
||||||
// after every common key in target's order (a precondition
|
// after every common key in target's order (a precondition
|
||||||
// for the fast path below, which only ever appends new keys
|
// for the fast path below, which only ever appends new keys
|
||||||
// at the very end): for an object_t whose iteration order is
|
// at the very end). Both are only needed for an object_t that
|
||||||
// a pure function of the key set (e.g. the default std::map,
|
// keeps its members in insertion order, such as the one
|
||||||
// which always iterates in sorted key order), the order
|
// backing `ordered_json`; for any other object_t, the fast
|
||||||
// check further below is always true and this whole
|
// path is always taken and they are not computed.
|
||||||
// mechanism is effectively a no-op; it only matters for a
|
|
||||||
// reorderable object_t such as the one backing `ordered_json`.
|
|
||||||
// patch ops for keys that were added (i.e., in target but not
|
// patch ops for keys that were added (i.e., in target but not
|
||||||
// in source); built here so the fast path below can reuse
|
// in source); built here so the fast path below can reuse
|
||||||
// them without a second source.find() per target key. Only
|
// them without a second source.find() per target key. Only
|
||||||
@@ -6179,11 +6177,21 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
common_keys_target_order.push_back(it.key());
|
#ifdef JSON_HEDLEY_MSVC_VERSION
|
||||||
if (seen_new_key)
|
#pragma warning(push )
|
||||||
|
#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr
|
||||||
|
#endif
|
||||||
|
if (detail::is_ordered_map<object_t>::value)
|
||||||
{
|
{
|
||||||
new_keys_form_suffix = false;
|
common_keys_target_order.push_back(it.key());
|
||||||
|
if (seen_new_key)
|
||||||
|
{
|
||||||
|
new_keys_form_suffix = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef JSON_HEDLEY_MSVC_VERSION
|
||||||
|
#pragma warning( pop )
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32231,12 +32231,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
// the same time, determine whether every added key comes
|
// the same time, determine whether every added key comes
|
||||||
// after every common key in target's order (a precondition
|
// after every common key in target's order (a precondition
|
||||||
// for the fast path below, which only ever appends new keys
|
// for the fast path below, which only ever appends new keys
|
||||||
// at the very end): for an object_t whose iteration order is
|
// at the very end). Both are only needed for an object_t that
|
||||||
// a pure function of the key set (e.g. the default std::map,
|
// keeps its members in insertion order, such as the one
|
||||||
// which always iterates in sorted key order), the order
|
// backing `ordered_json`; for any other object_t, the fast
|
||||||
// check further below is always true and this whole
|
// path is always taken and they are not computed.
|
||||||
// mechanism is effectively a no-op; it only matters for a
|
|
||||||
// reorderable object_t such as the one backing `ordered_json`.
|
|
||||||
// patch ops for keys that were added (i.e., in target but not
|
// patch ops for keys that were added (i.e., in target but not
|
||||||
// in source); built here so the fast path below can reuse
|
// in source); built here so the fast path below can reuse
|
||||||
// them without a second source.find() per target key. Only
|
// them without a second source.find() per target key. Only
|
||||||
@@ -32260,11 +32258,21 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
common_keys_target_order.push_back(it.key());
|
#ifdef JSON_HEDLEY_MSVC_VERSION
|
||||||
if (seen_new_key)
|
#pragma warning(push )
|
||||||
|
#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr
|
||||||
|
#endif
|
||||||
|
if (detail::is_ordered_map<object_t>::value)
|
||||||
{
|
{
|
||||||
new_keys_form_suffix = false;
|
common_keys_target_order.push_back(it.key());
|
||||||
|
if (seen_new_key)
|
||||||
|
{
|
||||||
|
new_keys_form_suffix = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef JSON_HEDLEY_MSVC_VERSION
|
||||||
|
#pragma warning( pop )
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user