diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/v8/src/objects/fixed-array-inl.h | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/objects/fixed-array-inl.h')
-rw-r--r-- | chromium/v8/src/objects/fixed-array-inl.h | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/chromium/v8/src/objects/fixed-array-inl.h b/chromium/v8/src/objects/fixed-array-inl.h index 174d4abc5b4..a49483ebc64 100644 --- a/chromium/v8/src/objects/fixed-array-inl.h +++ b/chromium/v8/src/objects/fixed-array-inl.h @@ -209,8 +209,13 @@ inline int WeakArrayList::AllocatedSize() { template <SearchMode search_mode, typename T> int BinarySearch(T* array, Name name, int valid_entries, int* out_insertion_index) { - DCHECK(search_mode == ALL_ENTRIES || out_insertion_index == nullptr); + DCHECK_IMPLIES(search_mode == VALID_ENTRIES, out_insertion_index == nullptr); int low = 0; + // We have to search on all entries, even when search_mode == VALID_ENTRIES. + // This is because the InternalIndex might be different from the SortedIndex + // (i.e the first added item in {array} could be the last in the sorted + // index). After doing the binary search and getting the correct internal + // index we check to have the index lower than valid_entries, if needed. int high = array->number_of_entries() - 1; uint32_t hash = name.hash_field(); int limit = high; @@ -234,6 +239,11 @@ int BinarySearch(T* array, Name name, int valid_entries, Name entry = array->GetKey(InternalIndex(sort_index)); uint32_t current_hash = entry.hash_field(); if (current_hash != hash) { + // 'search_mode == ALL_ENTRIES' here and below is not needed since + // 'out_insertion_index != nullptr' implies 'search_mode == ALL_ENTRIES'. + // Having said that, when creating the template for <VALID_ENTRIES> these + // ifs can be elided by the C++ compiler if we add 'search_mode == + // ALL_ENTRIES'. if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) { *out_insertion_index = sort_index + (current_hash > hash ? 0 : 1); } @@ -284,8 +294,9 @@ int LinearSearch(T* array, Name name, int valid_entries, } template <SearchMode search_mode, typename T> -int Search(T* array, Name name, int valid_entries, int* out_insertion_index) { - SLOW_DCHECK(array->IsSortedNoDuplicates()); +int Search(T* array, Name name, int valid_entries, int* out_insertion_index, + bool concurrent_search) { + SLOW_DCHECK_IMPLIES(!concurrent_search, array->IsSortedNoDuplicates()); if (valid_entries == 0) { if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) { @@ -294,14 +305,14 @@ int Search(T* array, Name name, int valid_entries, int* out_insertion_index) { return T::kNotFound; } - // Fast case: do linear search for small arrays. + // Do linear search for small arrays, and for searches in the background + // thread. const int kMaxElementsForLinearSearch = 8; - if (valid_entries <= kMaxElementsForLinearSearch) { + if (valid_entries <= kMaxElementsForLinearSearch || concurrent_search) { return LinearSearch<search_mode>(array, name, valid_entries, out_insertion_index); } - // Slow case: perform binary search. return BinarySearch<search_mode>(array, name, valid_entries, out_insertion_index); } |