llvm.org GIT mirror llvm / ac58a16
Fix PR1329. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36016 91177308-0d34-0410-b5e6-96231b3b80d8 Jeff Cohen 13 years ago
2 changed file(s) with 32 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
5252 unsigned NumElements;
5353 unsigned NumTombstones;
5454 void *SmallArray[1]; // Must be last ivar.
55
56 // Helper to copy construct a SmallPtrSet.
57 SmallPtrSetImpl(const SmallPtrSetImpl& that);
5558 public:
5659 SmallPtrSetImpl(unsigned SmallSize) {
5760 assert(SmallSize && (SmallSize & (SmallSize-1)) == 0 &&
213216 void *SmallArray[SmallSizePowTwo];
214217 public:
215218 SmallPtrSet() : SmallPtrSetImpl(NextPowerOfTwo::Val) {}
219 SmallPtrSet(const SmallPtrSet &that) : SmallPtrSetImpl(that) {}
216220
217221 template
218222 SmallPtrSet(It I, It E)
140140 }
141141
142142 delete [] OldBuckets;
143 NumTombstones = 0;
143144 }
144145 }
146
147 SmallPtrSetImpl::SmallPtrSetImpl(const SmallPtrSetImpl& that) {
148 NumElements = that.NumElements;
149 NumTombstones = 0;
150 if (that.isSmall()) {
151 CurArraySize = that.CurArraySize;
152 CurArray = &SmallArray[0];
153 memcpy(CurArray, that.CurArray, sizeof(void*)*CurArraySize);
154 } else {
155 CurArraySize = that.NumElements < 64 ? 128 : that.NumElements*2;
156 CurArray = new void*[CurArraySize+1];
157 memset(CurArray, -1, CurArraySize*sizeof(void*));
158
159 // The end pointer, always valid, is set to a valid element to help the
160 // iterator.
161 CurArray[CurArraySize] = 0;
162
163 // Copy over all valid entries.
164 for (void **BucketPtr = that.CurArray, **E = that.CurArray+CurArraySize;
165 BucketPtr != E; ++BucketPtr) {
166 // Copy over the element if it is valid.
167 void *Elt = *BucketPtr;
168 if (Elt != getTombstoneMarker() && Elt != getEmptyMarker())
169 *const_cast(FindBucketFor(Elt)) = Elt;
170 }
171 }
172 }