diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2011-03-30 18:32:44 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2011-03-30 18:32:44 +0000 |
commit | f587f4419c71f249e86c9217b8abf6197abe5ecb (patch) | |
tree | a19bd20ad114ab4af2b460be2fc78250156d7895 /llvm/lib/Support/StringMap.cpp | |
parent | 5ca05e18017ef75393faaaba7c75d8995e24f6ba (diff) | |
download | bcm5719-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.cpp | 14 |
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)); |