@@ -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 ();
@@ -219,8 +219,8 @@ class SmallPtrSetImplBase : public DebugEpochBase {
219219 bool contains_imp (const void *Ptr) const {
220220 if (isSmall ()) {
221221 // Linear search for the item.
222- const void *const *APtr = SmallArray ;
223- const void *const *E = SmallArray + NumNonEmpty;
222+ const void *const *APtr = CurArray ;
223+ const void *const *E = CurArray + NumNonEmpty;
224224 for (; APtr != E; ++APtr)
225225 if (*APtr == Ptr)
226226 return true ;
@@ -230,7 +230,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
230230 return doFind (Ptr) != nullptr ;
231231 }
232232
233- bool isSmall () const { return CurArray == SmallArray ; }
233+ bool isSmall () const { return IsSmall ; }
234234
235235private:
236236 std::pair<const void *const *, bool > insert_imp_big (const void *Ptr);
@@ -245,16 +245,19 @@ class SmallPtrSetImplBase : public DebugEpochBase {
245245protected:
246246 // / swap - Swaps the elements of two sets.
247247 // / Note: This method assumes that both sets have the same small size.
248- void swap (SmallPtrSetImplBase &RHS);
248+ void swap (const void **SmallStorage, const void **RHSSmallStorage,
249+ SmallPtrSetImplBase &RHS);
249250
250- void CopyFrom (const SmallPtrSetImplBase &RHS);
251- void MoveFrom (unsigned SmallSize, SmallPtrSetImplBase &&RHS);
251+ void copyFrom (const void **SmallStorage, const SmallPtrSetImplBase &RHS);
252+ void moveFrom (const void **SmallStorage, unsigned SmallSize,
253+ const void **RHSSmallStorage, SmallPtrSetImplBase &&RHS);
252254
253255private:
254- // / Code shared by MoveFrom() and move constructor.
255- void MoveHelper (unsigned SmallSize, SmallPtrSetImplBase &&RHS);
256- // / Code shared by CopyFrom() and copy constructor.
257- void CopyHelper (const SmallPtrSetImplBase &RHS);
256+ // / Code shared by moveFrom() and move constructor.
257+ void moveHelper (const void **SmallStorage, unsigned SmallSize,
258+ const void **RHSSmallStorage, SmallPtrSetImplBase &&RHS);
259+ // / Code shared by copyFrom() and copy constructor.
260+ void copyHelper (const SmallPtrSetImplBase &RHS);
258261};
259262
260263// / SmallPtrSetIteratorImpl - This is the common base class shared between all
@@ -415,7 +418,7 @@ class SmallPtrSetImpl : public SmallPtrSetImplBase {
415418 bool remove_if (UnaryPredicate P) {
416419 bool Removed = false ;
417420 if (isSmall ()) {
418- const void **APtr = SmallArray , **E = SmallArray + NumNonEmpty;
421+ const void **APtr = CurArray , **E = CurArray + NumNonEmpty;
419422 while (APtr != E) {
420423 PtrType Ptr = PtrTraits::getFromVoidPointer (const_cast <void *>(*APtr));
421424 if (P (Ptr)) {
@@ -540,7 +543,8 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
540543 SmallPtrSet () : BaseT(SmallStorage, SmallSizePowTwo) {}
541544 SmallPtrSet (const SmallPtrSet &that) : BaseT(SmallStorage, that) {}
542545 SmallPtrSet (SmallPtrSet &&that)
543- : BaseT(SmallStorage, SmallSizePowTwo, std::move(that)) {}
546+ : BaseT(SmallStorage, SmallSizePowTwo, that.SmallStorage,
547+ std::move (that)) {}
544548
545549 template <typename It>
546550 SmallPtrSet (It I, It E) : BaseT(SmallStorage, SmallSizePowTwo) {
@@ -555,14 +559,15 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
555559 SmallPtrSet<PtrType, SmallSize> &
556560 operator =(const SmallPtrSet<PtrType, SmallSize> &RHS) {
557561 if (&RHS != this )
558- this ->CopyFrom ( RHS);
562+ this ->copyFrom (SmallStorage, RHS);
559563 return *this ;
560564 }
561565
562566 SmallPtrSet<PtrType, SmallSize> &
563567 operator =(SmallPtrSet<PtrType, SmallSize> &&RHS) {
564568 if (&RHS != this )
565- this ->MoveFrom (SmallSizePowTwo, std::move (RHS));
569+ this ->moveFrom (SmallStorage, SmallSizePowTwo, RHS.SmallStorage ,
570+ std::move (RHS));
566571 return *this ;
567572 }
568573
@@ -575,7 +580,7 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
575580
576581 // / swap - Swaps the elements of two sets.
577582 void swap (SmallPtrSet<PtrType, SmallSize> &RHS) {
578- SmallPtrSetImplBase::swap (RHS);
583+ SmallPtrSetImplBase::swap (SmallStorage, RHS. SmallStorage , RHS);
579584 }
580585};
581586
0 commit comments