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/include | |
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/include')
-rw-r--r-- | llvm/include/llvm/ADT/StringMap.h | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h index bad0e6f5136..f3d6b9f4849 100644 --- a/llvm/include/llvm/ADT/StringMap.h +++ b/llvm/include/llvm/ADT/StringMap.h @@ -81,16 +81,6 @@ protected: StringMapImpl(unsigned InitSize, unsigned ItemSize); void RehashTable(); - /// ShouldRehash - Return true if the table should be rehashed after a new - /// element was recently inserted. - bool ShouldRehash() const { - // 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 the table. - return NumItems*4 > NumBuckets*3 || - NumBuckets-(NumItems+NumTombstones) < NumBuckets/8; - } - /// LookupBucketFor - Look up the bucket that the specified string should end /// up in. If it already exists as a key in the map, the Item pointer for the /// specified bucket will be non-null. Otherwise, it will be null. In either @@ -340,8 +330,7 @@ public: Bucket.Item = KeyValue; ++NumItems; - if (ShouldRehash()) - RehashTable(); + RehashTable(); return true; } @@ -383,8 +372,7 @@ public: // filled in by LookupBucketFor. Bucket.Item = NewItem; - if (ShouldRehash()) - RehashTable(); + RehashTable(); return *NewItem; } |