diff options
author | Owen Anderson <resistor@mac.com> | 2007-07-24 21:31:23 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2007-07-24 21:31:23 +0000 |
commit | 5be86a9ab6aba0c8ac1738e843741c2ec4c79db9 (patch) | |
tree | d93945adb257f783d3aadf5db6b1c97c91ff8b09 /lib | |
parent | f38d0d00d160dc689967c8056af057086313ccf9 (diff) | |
download | external_llvm-5be86a9ab6aba0c8ac1738e843741c2ec4c79db9.zip external_llvm-5be86a9ab6aba0c8ac1738e843741c2ec4c79db9.tar.gz external_llvm-5be86a9ab6aba0c8ac1738e843741c2ec4c79db9.tar.bz2 |
Make the copy constructor of SmallPtrSet much faster.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40474 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/SmallPtrSet.cpp | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp index 122a71d..3326923 100644 --- a/lib/Support/SmallPtrSet.cpp +++ b/lib/Support/SmallPtrSet.cpp @@ -149,33 +149,23 @@ void SmallPtrSetImpl::Grow() { } SmallPtrSetImpl::SmallPtrSetImpl(const SmallPtrSetImpl& that) { - NumElements = that.NumElements; - NumTombstones = 0; + // If we're becoming small, prepare to insert into our stack space if (that.isSmall()) { - CurArraySize = that.CurArraySize; CurArray = &SmallArray[0]; - // Copy the entire contents of the array, including the -1's and the null - // terminator. - memcpy(CurArray, that.CurArray, sizeof(void*)*(CurArraySize+1)); + // Otherwise, allocate new heap space (unless we were the same size) } else { - CurArraySize = that.NumElements < 64 ? 128 : that.CurArraySize*2; - CurArray = (void**)malloc(sizeof(void*) * (CurArraySize+1)); + CurArray = (void**)malloc(sizeof(void*) * (that.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; - - // Copy over all valid entries. - for (void **BucketPtr = that.CurArray, **E = that.CurArray+that.CurArraySize; - BucketPtr != E; ++BucketPtr) { - // Copy over the element if it is valid. - void *Elt = *BucketPtr; - if (Elt != getTombstoneMarker() && Elt != getEmptyMarker()) - *const_cast<void**>(FindBucketFor(Elt)) = Elt; - } } + + // Copy over the new array size + CurArraySize = that.CurArraySize; + + // Copy over the contents from the other set + memcpy(CurArray, that.CurArray, sizeof(void*)*(CurArraySize+1)); + + NumElements = that.NumElements; + NumTombstones = that.NumTombstones; } /// CopyFrom - implement operator= from a smallptrset that has the same pointer |