LibWeb: Use binary search for IndexedDB ObjectStore key lookup

Use AK::binary_search instead of a linear find_if scan in
has_record_with_key(), taking advantage of the fact that records
are kept sorted by key.
This commit is contained in:
Andreas Kling
2026-03-20 23:33:25 -05:00
committed by Andreas Kling
parent 9eeb43e265
commit 383366bcf7
Notes: github-actions[bot] 2026-03-21 13:42:38 +00:00

View File

@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/BinarySearch.h>
#include <AK/Math.h>
#include <LibWeb/IndexedDB/IDBKeyRange.h>
#include <LibWeb/IndexedDB/Internal/MutationLog.h>
@@ -82,11 +83,9 @@ void ObjectStore::remove_record_with_key(GC::Ref<Key> key)
bool ObjectStore::has_record_with_key(GC::Ref<Key> key)
{
auto index = m_records.find_if([&key](auto const& record) {
return Key::equals(key, record.key);
});
return index != m_records.end();
return binary_search(m_records, key, nullptr, [](auto const& needle, auto const& record) -> int {
return Key::compare_two_keys(needle, record.key);
}) != nullptr;
}
void ObjectStore::store_a_record(ObjectStoreRecord const& record)