aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/StringMap.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2011-03-30 18:32:44 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2011-03-30 18:32:44 +0000
commitaea4fe2862ce17acc6ce943df589ee8d5eb05adf (patch)
tree20475d051ea65b71edd9690bc4092388cc64fbef /lib/Support/StringMap.cpp
parent414fdbdb0104fdc8c570287f94df8bb697e7b7c1 (diff)
downloadexternal_llvm-aea4fe2862ce17acc6ce943df589ee8d5eb05adf.zip
external_llvm-aea4fe2862ce17acc6ce943df589ee8d5eb05adf.tar.gz
external_llvm-aea4fe2862ce17acc6ce943df589ee8d5eb05adf.tar.bz2
Prevent infinite growth of SmallMap instances.
Rehash but don't grow when full of tombstones. Patch by José Fonseca! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128565 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/StringMap.cpp')
-rw-r--r--lib/Support/StringMap.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/Support/StringMap.cpp b/lib/Support/StringMap.cpp
index 90ec299..f193aa4 100644
--- a/lib/Support/StringMap.cpp
+++ b/lib/Support/StringMap.cpp
@@ -177,7 +177,19 @@ StringMapEntryBase *StringMapImpl::RemoveKey(StringRef Key) {
/// RehashTable - Grow the table, redistributing values into the buckets with
/// the appropriate mod-of-hashtable-size.
void StringMapImpl::RehashTable() {
- unsigned NewSize = NumBuckets*2;
+ unsigned NewSize;
+
+ // If the hash table is now more than 3/4 full, or if fewer than 1/8 of
+ // the buckets are empty (meaning that many are filled with tombstones),
+ // grow/rehash the table.
+ if (NumItems*4 > NumBuckets*3) {
+ NewSize = NumBuckets*2;
+ } else if (NumBuckets-(NumItems+NumTombstones) < NumBuckets/8) {
+ NewSize = NumBuckets;
+ } else {
+ return;
+ }
+
// Allocate one extra bucket which will always be non-empty. This allows the
// iterators to stop at end.
ItemBucket *NewTableArray =(ItemBucket*)calloc(NewSize+1, sizeof(ItemBucket));