do not let the table fill up with tombstones.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33973 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/ADT/SmallPtrSet.h b/include/llvm/ADT/SmallPtrSet.h
index ed7f4da..1db2945 100644
--- a/include/llvm/ADT/SmallPtrSet.h
+++ b/include/llvm/ADT/SmallPtrSet.h
@@ -51,6 +51,7 @@
// If small, this is # elts allocated consequtively
unsigned NumElements;
+ unsigned NumTombstones;
void *SmallArray[1]; // Must be last ivar.
public:
SmallPtrSetImpl(unsigned SmallSize) {
@@ -82,6 +83,7 @@
// Fill the array with empty markers.
memset(CurArray, -1, CurArraySize*sizeof(void*));
NumElements = 0;
+ NumTombstones = 0;
}
/// insert - This returns true if the pointer was new to the set, false if it
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp
index 758a952..98d5bc9 100644
--- a/lib/Support/SmallPtrSet.cpp
+++ b/lib/Support/SmallPtrSet.cpp
@@ -32,7 +32,8 @@
}
// If more than 3/4 of the array is full, grow.
- if (NumElements*4 >= CurArraySize*3)
+ if (NumElements*4 >= CurArraySize*3 ||
+ CurArraySize-(NumElements+NumTombstones) < CurArraySize/8)
Grow();
// Okay, we know we have space. Find a hash bucket.
@@ -40,6 +41,8 @@
if (*Bucket == Ptr) return false; // Already inserted, good.
// Otherwise, insert it!
+ if (*Bucket == getTombstoneMarker())
+ --NumTombstones;
*Bucket = Ptr;
++NumElements; // Track density.
return true;
@@ -69,6 +72,7 @@
// Set this as a tombstone.
*Bucket = getTombstoneMarker();
--NumElements;
+ ++NumTombstones;
return true;
}