Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: third_party/WebKit/Source/wtf/HashTable.h

Issue 2034883002: Shrink weak hash tables when adding elements, if needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment typo Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/HashTable.h
diff --git a/third_party/WebKit/Source/wtf/HashTable.h b/third_party/WebKit/Source/wtf/HashTable.h
index 1930eb03f2e42418977c19ce812b90a0ee4d59f9..014771f50bd1e50212c6295d956dc44a7ece6f75 100644
--- a/third_party/WebKit/Source/wtf/HashTable.h
+++ b/third_party/WebKit/Source/wtf/HashTable.h
@@ -855,8 +855,23 @@ typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
++m_keyCount;
- if (shouldExpand())
+ if (shouldExpand()) {
entry = expand(entry);
+ } else if (Traits::weakHandlingFlag == WeakHandlingInCollections && shouldShrink()) {
+ // When weak hash tables are processed by the garbage collector,
+ // elements with no other strong references to them will have their
+ // table entries cleared. But no shrinking of the backing store is
+ // allowed at that time, as allocations are prohibited during that
+ // GC phase.
+ //
+ // With that weak processing taking care of removals, explicit
+ // remove()s of elements is rarely done. Which implies that the
+ // weak hash table will never be checked if it can be shrunk.
+ //
+ // To prevent weak hash tables with very low load factors from
+ // developing, we perform it when adding elements instead.
+ entry = rehash(m_tableSize / 2, entry);
+ }
return AddResult(this, entry, true);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698