aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT/SmallPtrSet.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-05 07:32:14 +0000
committerChris Lattner <sabre@nondot.org>2007-08-05 07:32:14 +0000
commit42e4bdf2577946380ce1529d5716e48b33d4186d (patch)
tree3a77344832b30c3317ca27bc483ca7690d4e7dc8 /include/llvm/ADT/SmallPtrSet.h
parenta31965301da89a7d0c829bded72c6b0da0303c54 (diff)
downloadexternal_llvm-42e4bdf2577946380ce1529d5716e48b33d4186d.zip
external_llvm-42e4bdf2577946380ce1529d5716e48b33d4186d.tar.gz
external_llvm-42e4bdf2577946380ce1529d5716e48b33d4186d.tar.bz2
When clearing a SmallPtrSet, if the set had a huge capacity, but the
contents of the set were small, deallocate and shrink the set. This avoids having us to memset as much data, significantly speeding up some pathological cases. For example, this speeds up the verifier from 0.3899s to 0.0763 (5.1x) on the testcase from PR1432 in a release build. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40837 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/SmallPtrSet.h')
-rw-r--r--include/llvm/ADT/SmallPtrSet.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/include/llvm/ADT/SmallPtrSet.h b/include/llvm/ADT/SmallPtrSet.h
index e39a4fe..2ff7de4 100644
--- a/include/llvm/ADT/SmallPtrSet.h
+++ b/include/llvm/ADT/SmallPtrSet.h
@@ -80,6 +80,11 @@ public:
}
void clear() {
+ // If the capacity of the array is huge, and the # elements used is small,
+ // shrink the array.
+ if (!isSmall() && NumElements*4 < CurArraySize && CurArraySize > 32)
+ return shrink_and_clear();
+
// Fill the array with empty markers.
memset(CurArray, -1, CurArraySize*sizeof(void*));
NumElements = 0;
@@ -103,8 +108,8 @@ public:
bool count(void * const Ptr) const {
if (isSmall()) {
// Linear search for the item.
- for (const void *const *APtr = SmallArray, *const *E = SmallArray+NumElements;
- APtr != E; ++APtr)
+ for (const void *const *APtr = SmallArray,
+ *const *E = SmallArray+NumElements; APtr != E; ++APtr)
if (*APtr == Ptr)
return true;
return false;
@@ -121,6 +126,7 @@ private:
return ((uintptr_t)Ptr >> 4) & (CurArraySize-1);
}
const void * const *FindBucketFor(const void *Ptr) const;
+ void shrink_and_clear();
/// Grow - Allocate a larger backing store for the buckets and move it over.
void Grow();