mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-19 15:13:49 -04:00
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
This commit is contained in:
@@ -18,6 +18,24 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
void SmallPtrSetImpl::shrink_and_clear() {
|
||||
assert(!isSmall() && "Can't shrink a small set!");
|
||||
free(CurArray);
|
||||
|
||||
// Reduce the number of buckets.
|
||||
CurArraySize = NumElements > 16 ? 1 << (Log2_32_Ceil(NumElements) + 1) : 32;
|
||||
NumElements = NumTombstones = 0;
|
||||
|
||||
// Install the new array. Clear all the buckets to empty.
|
||||
CurArray = (const void**)malloc(sizeof(void*) * (CurArraySize+1));
|
||||
assert(CurArray && "Failed to allocate memory?");
|
||||
memset(CurArray, -1, CurArraySize*sizeof(void*));
|
||||
|
||||
// The end pointer, always valid, is set to a valid element to help the
|
||||
// iterator.
|
||||
CurArray[CurArraySize] = 0;
|
||||
}
|
||||
|
||||
bool SmallPtrSetImpl::insert(const void * Ptr) {
|
||||
if (isSmall()) {
|
||||
// Check to see if it is already in the set.
|
||||
|
||||
Reference in New Issue
Block a user