@@ -53,10 +53,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
5353 friend class SmallPtrSetIteratorImpl ;
5454
5555protected:
56- // / SmallArray - Points to a fixed size set of buckets, used in 'small mode'.
57- const void **SmallArray;
58- // / CurArray - This is the current set of buckets. If equal to SmallArray,
59- // / then the set is in 'small mode'.
56+ // / The current set of buckets, in either small or big representation.
6057 const void **CurArray;
6158 // / CurArraySize - The allocated size of CurArray, always a power of two.
6259 unsigned CurArraySize;
@@ -67,16 +64,18 @@ class SmallPtrSetImplBase : public DebugEpochBase {
6764 unsigned NumNonEmpty;
6865 // / Number of tombstones in CurArray.
6966 unsigned NumTombstones;
67+ // / Whether the set is in small representation.
68+ bool IsSmall;
7069
7170 // Helpers to copy and move construct a SmallPtrSet.
7271 SmallPtrSetImplBase (const void **SmallStorage,
7372 const SmallPtrSetImplBase &that);
7473 SmallPtrSetImplBase (const void **SmallStorage, unsigned SmallSize,
75- SmallPtrSetImplBase &&that);
74+ const void **RHSSmallStorage, SmallPtrSetImplBase &&that);
7675
7776 explicit SmallPtrSetImplBase (const void **SmallStorage, unsigned SmallSize)
78- : SmallArray (SmallStorage), CurArray(SmallStorage ),
79- CurArraySize(SmallSize), NumNonEmpty( 0 ), NumTombstones( 0 ) {
77+ : CurArray (SmallStorage), CurArraySize(SmallSize), NumNonEmpty( 0 ),
78+ NumTombstones( 0 ), IsSmall( true ) {
8079 assert (SmallSize && (SmallSize & (SmallSize-1 )) == 0 &&
8180 " Initial size must be a power of two!" );
8281 }
@@ -150,7 +149,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
150149 std::pair<const void *const *, bool > insert_imp (const void *Ptr) {
151150 if (isSmall ()) {
152151 // Check to see if it is already in the set.
153- for (const void **APtr = SmallArray , **E = SmallArray + NumNonEmpty;
152+ for (const void **APtr = CurArray , **E = CurArray + NumNonEmpty;
154153 APtr != E; ++APtr) {
155154 const void *Value = *APtr;
156155 if (Value == Ptr)
@@ -159,9 +158,9 @@ class SmallPtrSetImplBase : public DebugEpochBase {
159158
160159 // Nope, there isn't. If we stay small, just 'pushback' now.
161160 if (NumNonEmpty < CurArraySize) {
162- SmallArray [NumNonEmpty++] = Ptr;
161+ CurArray [NumNonEmpty++] = Ptr;
163162 incrementEpoch ();
164- return std::make_pair (SmallArray + (NumNonEmpty - 1 ), true );
163+ return std::make_pair (CurArray + (NumNonEmpty - 1 ), true );
165164 }
166165 // Otherwise, hit the big set case, which will call grow.
167166 }
@@ -174,10 +173,10 @@ class SmallPtrSetImplBase : public DebugEpochBase {
174173 // / in.
175174 bool erase_imp (const void * Ptr) {
176175 if (isSmall ()) {
177- for (const void **APtr = SmallArray , **E = SmallArray + NumNonEmpty;
176+ for (const void **APtr = CurArray , **E = CurArray + NumNonEmpty;
178177 APtr != E; ++APtr) {
179178 if (*APtr == Ptr) {
180- *APtr = SmallArray [--NumNonEmpty];
179+ *APtr = CurArray [--NumNonEmpty];
181180 incrementEpoch ();
182181 return true ;
183182 }
@@ -203,8 +202,9 @@ class SmallPtrSetImplBase : public DebugEpochBase {
203202 const void *const * find_imp (const void * Ptr) const {
204203 if (isSmall ()) {
205204 // Linear search for the item.
206- for (const void *const *APtr = SmallArray,
207- *const *E = SmallArray + NumNonEmpty; APtr != E; ++APtr)
205+ for (const void *const *APtr = CurArray, *const *E =
206+ CurArray + NumNonEmpty;
207+ APtr != E; ++APtr)
208208 if (*APtr == Ptr)
209209 return APtr;
210210 return EndPointer ();
@@ -216,7 +216,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
216216 return EndPointer ();
217217 }
218218
219- bool isSmall () const { return CurArray == SmallArray ; }
219+ bool isSmall () const { return IsSmall ; }
220220
221221private:
222222 std::pair<const void *const *, bool > insert_imp_big (const void *Ptr);
@@ -231,14 +231,17 @@ class SmallPtrSetImplBase : public DebugEpochBase {
231231protected:
232232 // / swap - Swaps the elements of two sets.
233233 // / Note: This method assumes that both sets have the same small size.
234- void swap (SmallPtrSetImplBase &RHS);
234+ void swap (const void **SmallStorage, const void **RHSSmallStorage,
235+ SmallPtrSetImplBase &RHS);
235236
236- void CopyFrom (const SmallPtrSetImplBase &RHS);
237- void MoveFrom (unsigned SmallSize, SmallPtrSetImplBase &&RHS);
237+ void CopyFrom (const void **SmallStorage, const SmallPtrSetImplBase &RHS);
238+ void MoveFrom (const void **SmallStorage, unsigned SmallSize,
239+ const void **RHSSmallStorage, SmallPtrSetImplBase &&RHS);
238240
239241private:
240242 // / Code shared by MoveFrom() and move constructor.
241- void MoveHelper (unsigned SmallSize, SmallPtrSetImplBase &&RHS);
243+ void MoveHelper (const void **SmallStorage, unsigned SmallSize,
244+ const void **RHSSmallStorage, SmallPtrSetImplBase &&RHS);
242245 // / Code shared by CopyFrom() and copy constructor.
243246 void CopyHelper (const SmallPtrSetImplBase &RHS);
244247};
@@ -401,7 +404,7 @@ class SmallPtrSetImpl : public SmallPtrSetImplBase {
401404 bool remove_if (UnaryPredicate P) {
402405 bool Removed = false ;
403406 if (isSmall ()) {
404- const void **APtr = SmallArray , **E = SmallArray + NumNonEmpty;
407+ const void **APtr = CurArray , **E = CurArray + NumNonEmpty;
405408 while (APtr != E) {
406409 PtrType Ptr = PtrTraits::getFromVoidPointer (const_cast <void *>(*APtr));
407410 if (P (Ptr)) {
@@ -526,7 +529,8 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
526529 SmallPtrSet () : BaseT(SmallStorage, SmallSizePowTwo) {}
527530 SmallPtrSet (const SmallPtrSet &that) : BaseT(SmallStorage, that) {}
528531 SmallPtrSet (SmallPtrSet &&that)
529- : BaseT(SmallStorage, SmallSizePowTwo, std::move(that)) {}
532+ : BaseT(SmallStorage, SmallSizePowTwo, that.SmallStorage,
533+ std::move (that)) {}
530534
531535 template <typename It>
532536 SmallPtrSet (It I, It E) : BaseT(SmallStorage, SmallSizePowTwo) {
@@ -541,14 +545,15 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
541545 SmallPtrSet<PtrType, SmallSize> &
542546 operator =(const SmallPtrSet<PtrType, SmallSize> &RHS) {
543547 if (&RHS != this )
544- this ->CopyFrom (RHS);
548+ this ->CopyFrom (SmallStorage, RHS);
545549 return *this ;
546550 }
547551
548552 SmallPtrSet<PtrType, SmallSize> &
549553 operator =(SmallPtrSet<PtrType, SmallSize> &&RHS) {
550554 if (&RHS != this )
551- this ->MoveFrom (SmallSizePowTwo, std::move (RHS));
555+ this ->MoveFrom (SmallStorage, SmallSizePowTwo, RHS.SmallStorage ,
556+ std::move (RHS));
552557 return *this ;
553558 }
554559
@@ -561,7 +566,7 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
561566
562567 // / swap - Swaps the elements of two sets.
563568 void swap (SmallPtrSet<PtrType, SmallSize> &RHS) {
564- SmallPtrSetImplBase::swap (RHS);
569+ SmallPtrSetImplBase::swap (SmallStorage, RHS. SmallStorage , RHS);
565570 }
566571};
567572
0 commit comments