summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-09 16:54:03 +0000
committerChris Lattner <sabre@nondot.org>2007-07-09 16:54:03 +0000
commit85049a470e18e23ae4f09b09a334a3d9a29fddbf (patch)
tree3136fb1893084228066bcb4427bc8a29fd3110e7 /llvm/lib/Support
parent56b01eb3d907436e133bf1a3b8b58ef22fa4c554 (diff)
downloadbcm5719-llvm-85049a470e18e23ae4f09b09a334a3d9a29fddbf.tar.gz
bcm5719-llvm-85049a470e18e23ae4f09b09a334a3d9a29fddbf.zip
implement operator= for smallptrset
llvm-svn: 38460
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index da1a11029e7..81c4bc752fb 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/lib/Support/SmallPtrSet.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/MathExtras.h"
using namespace llvm;
bool SmallPtrSetImpl::insert(void *Ptr) {
@@ -172,3 +173,38 @@ SmallPtrSetImpl::SmallPtrSetImpl(const SmallPtrSetImpl& that) {
}
}
}
+
+/// CopyFrom - implement operator= from a smallptrset that has the same pointer
+/// type, but may have a different small size.
+void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
+ // Allocate space if needed or clear the current elements out of the array.
+ if (CurArraySize < RHS.size()*2) {
+ if (!isSmall())
+ delete [] CurArray;
+
+ // Get a power of two larger than twice the RHS size.
+ CurArraySize = 1 << Log2_32(RHS.size()*4);
+
+ // Install the new array. Clear all the buckets to empty.
+ CurArray = new void*[CurArraySize+1];
+ memset(CurArray, -1, CurArraySize*sizeof(void*));
+
+ // The end pointer, always valid, is set to a valid element to help the
+ // iterator.
+ CurArray[CurArraySize] = 0;
+
+ } else if (!empty()) {
+ clear();
+ }
+
+ // Now that we know we have enough space, and that the current array is empty,
+ // copy over all the elements from the RHS.
+
+ for (void **BucketPtr = RHS.CurArray, **E = RHS.CurArray+RHS.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;
+ }
+}
OpenPOWER on IntegriCloud