mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 19:47:17 +02:00
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:
committed by
Andreas Kling
parent
9eeb43e265
commit
383366bcf7
Notes:
github-actions[bot]
2026-03-21 13:42:38 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/383366bcf71 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8546 Reviewed-by: https://github.com/tcl3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user