diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-11-19 07:49:26 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-11-19 07:49:26 +0000 |
commit | 70573dcd9f002307584b63033e6e017474e11b0c (patch) | |
tree | 0c227393f46738f668ebe94ec0b0c4132b661b55 /llvm/lib/Support/SmallPtrSet.cpp | |
parent | 2aa06a989dfef2950ab45da80dd9c1adadd9f9a2 (diff) | |
download | llvm-70573dcd9f002307584b63033e6e017474e11b0c.zip llvm-70573dcd9f002307584b63033e6e017474e11b0c.tar.gz llvm-70573dcd9f002307584b63033e6e017474e11b0c.tar.bz2 |
Update SetVector to rely on the underlying set's insert to return a pair<iterator, bool>
This is to be consistent with StringSet and ultimately with the standard
library's associative container insert function.
This lead to updating SmallSet::insert to return pair<iterator, bool>,
and then to update SmallPtrSet::insert to return pair<iterator, bool>,
and then to update all the existing users of those functions...
llvm-svn: 222334
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | llvm/lib/Support/SmallPtrSet.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp index 621b90f..c87ee7d 100644 --- a/llvm/lib/Support/SmallPtrSet.cpp +++ b/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) { 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) { |