From e1a2a1654841047070f90a2f899c5d97d6569f64 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 18 Oct 2026 22:24:18 +0200 Subject: [PATCH] Compare keys with key_equals() in the object hash index As the linear lookups do since the second review round of #5622. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/object_index.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/nlohmann/detail/view/object_index.hpp b/include/nlohmann/detail/view/object_index.hpp index a2ffcbab6..5c7551fe9 100644 --- a/include/nlohmann/detail/view/object_index.hpp +++ b/include/nlohmann/detail/view/object_index.hpp @@ -10,7 +10,6 @@ #include // size_t #include // uint32_t, uint64_t -#include // memcmp #include #include @@ -94,7 +93,7 @@ inline void build_object_index(document_data& d, node* obj) while (table[slot] != 0) { const node* const other = obj + table[slot]; - if (other->len == k->len && (k->len == 0 || std::memcmp(d.str(*other), key, k->len) == 0)) + if (d.key_equals(*other, key, k->len)) { duplicate = true; // keep the first break; @@ -141,7 +140,7 @@ inline const node* find_indexed(const document_data& d, const node* obj, const c return nullptr; } const node* const k = obj + s; - if (k->len == n && (n == 0 || std::memcmp(d.str(*k), key, n) == 0)) + if (d.key_equals(*k, key, n)) { return k; }