summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-07 01:11:25 +0000
committerChris Lattner <sabre@nondot.org>2007-02-07 01:11:25 +0000
commite346767f06fc485320b09adbed4e3720236cc1f8 (patch)
treeb4883b4df7865f290b1c08f06e93e1fddebe087c /llvm
parentdf0d5a1836ae869e51562d7c6c3926931c0ba5f3 (diff)
downloadbcm5719-llvm-e346767f06fc485320b09adbed4e3720236cc1f8.tar.gz
bcm5719-llvm-e346767f06fc485320b09adbed4e3720236cc1f8.zip
do not let the table fill up with tombstones.
llvm-svn: 33973
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ADT/SmallPtrSet.h2
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp6
2 files changed, 7 insertions, 1 deletions
diff --git a/llvm/include/llvm/ADT/SmallPtrSet.h b/llvm/include/llvm/ADT/SmallPtrSet.h
index ed7f4da4e1a..1db2945877a 100644
--- a/llvm/include/llvm/ADT/SmallPtrSet.h
+++ b/llvm/include/llvm/ADT/SmallPtrSet.h
@@ -51,6 +51,7 @@ protected:
// 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 @@ public:
// 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/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index 758a952ae42..98d5bc99adc 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/lib/Support/SmallPtrSet.cpp
@@ -32,7 +32,8 @@ bool SmallPtrSetImpl::insert(void *Ptr) {
}
// 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 @@ bool SmallPtrSetImpl::insert(void *Ptr) {
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 @@ bool SmallPtrSetImpl::erase(void *Ptr) {
// Set this as a tombstone.
*Bucket = getTombstoneMarker();
--NumElements;
+ ++NumTombstones;
return true;
}
OpenPOWER on IntegriCloud