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 <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-18 22:24:18 +02:00
1 parent d6712df6a1
commit e1a2a16548
1 file changed
+2 -3
@@ -10,7 +10,6 @@
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint32_t, uint64_t #include <cstdint> // uint32_t, uint64_t
#include <cstring> // memcmp
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <nlohmann/detail/view/document_data.hpp> #include <nlohmann/detail/view/document_data.hpp>
@@ -94,7 +93,7 @@ inline void build_object_index(document_data& d, node* obj)
while (table[slot] != 0) while (table[slot] != 0)
{ {
const node* const other = obj + table[slot]; 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 duplicate = true; // keep the first
break; break;
@@ -141,7 +140,7 @@ inline const node* find_indexed(const document_data& d, const node* obj, const c
return nullptr; return nullptr;
} }
const node* const k = obj + s; 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; return k;
} }