diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2011-03-30 18:32:48 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2011-03-30 18:32:48 +0000 |
commit | bdc1b01217441962f3547b847c35b629e534638e (patch) | |
tree | ce1f2bc5d25594fe005f88a6487067d4a5da9571 /llvm/lib/Support/SmallPtrSet.cpp | |
parent | f587f4419c71f249e86c9217b8abf6197abe5ecb (diff) | |
download | bcm5719-llvm-bdc1b01217441962f3547b847c35b629e534638e.tar.gz bcm5719-llvm-bdc1b01217441962f3547b847c35b629e534638e.zip |
Prevent infinite growth of SmallPtrSet instances.
Rehash but don't grow when full of tombstones.
Patch by José Fonseca!
llvm-svn: 128566
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | llvm/lib/Support/SmallPtrSet.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp index 504e6497a3c..997ce0b74cd 100644 --- a/llvm/lib/Support/SmallPtrSet.cpp +++ b/llvm/lib/Support/SmallPtrSet.cpp @@ -52,10 +52,14 @@ bool SmallPtrSetImpl::insert_imp(const void * Ptr) { // Otherwise, hit the big set case, which will call grow. } - // If more than 3/4 of the array is full, grow. - if (NumElements*4 >= CurArraySize*3 || - CurArraySize-(NumElements+NumTombstones) < CurArraySize/8) - Grow(); + if (NumElements*4 >= CurArraySize*3) { + // If more than 3/4 of the array is full, grow. + Grow(CurArraySize < 64 ? 128 : CurArraySize*2); + } else if (CurArraySize-(NumElements+NumTombstones) < CurArraySize/8) { + // If fewer of 1/8 of the array is empty (meaning that many are filled with + // tombstones), rehash. + Grow(CurArraySize); + } // Okay, we know we have space. Find a hash bucket. const void **Bucket = const_cast<const void**>(FindBucketFor(Ptr)); @@ -125,10 +129,9 @@ const void * const *SmallPtrSetImpl::FindBucketFor(const void *Ptr) const { /// Grow - Allocate a larger backing store for the buckets and move it over. /// -void SmallPtrSetImpl::Grow() { +void SmallPtrSetImpl::Grow(unsigned NewSize) { // Allocate at twice as many buckets, but at least 128. unsigned OldSize = CurArraySize; - unsigned NewSize = OldSize < 64 ? 128 : OldSize*2; const void **OldBuckets = CurArray; bool WasSmall = isSmall(); |