diff options
Diffstat (limited to 'contrib/llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/SmallPtrSet.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/contrib/llvm/lib/Support/SmallPtrSet.cpp b/contrib/llvm/lib/Support/SmallPtrSet.cpp index a80e095..c87ee7d 100644 --- a/contrib/llvm/lib/Support/SmallPtrSet.cpp +++ b/contrib/llvm/lib/Support/SmallPtrSet.cpp @@ -34,18 +34,19 @@ void SmallPtrSetImplBase::shrink_and_clear() { memset(CurArray, -1, CurArraySize*sizeof(void*)); } -bool SmallPtrSetImplBase::insert_imp(const void * Ptr) { +std::pair<const void *const *, bool> +SmallPtrSetImplBase::insert_imp(const void *Ptr) { if (isSmall()) { // Check to see if it is already in the set. for (const void **APtr = SmallArray, **E = SmallArray+NumElements; APtr != E; ++APtr) if (*APtr == Ptr) - return false; - + return std::make_pair(APtr, false); + // Nope, there isn't. If we stay small, just 'pushback' now. - if (NumElements < CurArraySize-1) { + if (NumElements < CurArraySize) { SmallArray[NumElements++] = Ptr; - return true; + return std::make_pair(SmallArray + (NumElements - 1), true); } // Otherwise, hit the big set case, which will call grow. } @@ -61,14 +62,15 @@ bool SmallPtrSetImplBase::insert_imp(const void * Ptr) { // Okay, we know we have space. Find a hash bucket. const void **Bucket = const_cast<const void**>(FindBucketFor(Ptr)); - if (*Bucket == Ptr) return false; // Already inserted, good. - + if (*Bucket == Ptr) + return std::make_pair(Bucket, false); // Already inserted, good. + // Otherwise, insert it! if (*Bucket == getTombstoneMarker()) --NumTombstones; *Bucket = Ptr; ++NumElements; // Track density. - return true; + return std::make_pair(Bucket, true); } bool SmallPtrSetImplBase::erase_imp(const void * Ptr) { @@ -200,13 +202,12 @@ SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage, if (that.isSmall()) { CurArray = SmallArray; memcpy(CurArray, that.CurArray, sizeof(void *) * CurArraySize); - return; + } else { + // Otherwise, we steal the large memory allocation and no copy is needed. + CurArray = that.CurArray; + that.CurArray = that.SmallArray; } - // Otherwise, we steal the large memory allocation and no copy is needed. - CurArray = that.CurArray; - that.CurArray = that.SmallArray; - // Make the "that" object small and empty. that.CurArraySize = SmallSize; assert(that.CurArray == that.SmallArray); |