summaryrefslogtreecommitdiffstats
path: root/llvm/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
commitf587f4419c71f249e86c9217b8abf6197abe5ecb (patch)
treea19bd20ad114ab4af2b460be2fc78250156d7895 /llvm/lib/Support/StringMap.cpp
parent5ca05e18017ef75393faaaba7c75d8995e24f6ba (diff)
downloadbcm5719-llvm-f587f4419c71f249e86c9217b8abf6197abe5ecb.tar.gz
bcm5719-llvm-f587f4419c71f249e86c9217b8abf6197abe5ecb.zip
Prevent infinite growth of SmallMap instances.
Rehash but don't grow when full of tombstones. Patch by José Fonseca! llvm-svn: 128565
Diffstat (limited to 'llvm/lib/Support/StringMap.cpp')
-rw-r--r--llvm/lib/Support/StringMap.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
index 90ec2995026..f193aa42a44 100644
--- a/llvm/lib/Support/StringMap.cpp
+++ b/llvm/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));
OpenPOWER on IntegriCloud