@@ -53,10 +53,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
53
53
friend class SmallPtrSetIteratorImpl ;
54
54
55
55
protected:
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.
60
57
const void **CurArray;
61
58
// / CurArraySize - The allocated size of CurArray, always a power of two.
62
59
unsigned CurArraySize;
@@ -67,16 +64,18 @@ class SmallPtrSetImplBase : public DebugEpochBase {
67
64
unsigned NumNonEmpty;
68
65
// / Number of tombstones in CurArray.
69
66
unsigned NumTombstones;
67
+ // / Whether the set is in small representation.
68
+ bool IsSmall;
70
69
71
70
// Helpers to copy and move construct a SmallPtrSet.
72
71
SmallPtrSetImplBase (const void **SmallStorage,
73
72
const SmallPtrSetImplBase &that);
74
73
SmallPtrSetImplBase (const void **SmallStorage, unsigned SmallSize,
75
- SmallPtrSetImplBase &&that);
74
+ const void **RHSSmallStorage, SmallPtrSetImplBase &&that);
76
75
77
76
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 ) {
80
79
assert (SmallSize && (SmallSize & (SmallSize-1 )) == 0 &&
81
80
" Initial size must be a power of two!" );
82
81
}
@@ -150,7 +149,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
150
149
std::pair<const void *const *, bool > insert_imp (const void *Ptr) {
151
150
if (isSmall ()) {
152
151
// 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;
154
153
APtr != E; ++APtr) {
155
154
const void *Value = *APtr;
156
155
if (Value == Ptr)
@@ -159,9 +158,9 @@ class SmallPtrSetImplBase : public DebugEpochBase {
159
158
160
159
// Nope, there isn't. If we stay small, just 'pushback' now.
161
160
if (NumNonEmpty < CurArraySize) {
162
- SmallArray [NumNonEmpty++] = Ptr;
161
+ CurArray [NumNonEmpty++] = Ptr;
163
162
incrementEpoch ();
164
- return std::make_pair (SmallArray + (NumNonEmpty - 1 ), true );
163
+ return std::make_pair (CurArray + (NumNonEmpty - 1 ), true );
165
164
}
166
165
// Otherwise, hit the big set case, which will call grow.
167
166
}
@@ -174,10 +173,10 @@ class SmallPtrSetImplBase : public DebugEpochBase {
174
173
// / in.
175
174
bool erase_imp (const void * Ptr) {
176
175
if (isSmall ()) {
177
- for (const void **APtr = SmallArray , **E = SmallArray + NumNonEmpty;
176
+ for (const void **APtr = CurArray , **E = CurArray + NumNonEmpty;
178
177
APtr != E; ++APtr) {
179
178
if (*APtr == Ptr) {
180
- *APtr = SmallArray [--NumNonEmpty];
179
+ *APtr = CurArray [--NumNonEmpty];
181
180
incrementEpoch ();
182
181
return true ;
183
182
}
@@ -203,8 +202,9 @@ class SmallPtrSetImplBase : public DebugEpochBase {
203
202
const void *const * find_imp (const void * Ptr) const {
204
203
if (isSmall ()) {
205
204
// 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)
208
208
if (*APtr == Ptr)
209
209
return APtr;
210
210
return EndPointer ();
@@ -219,8 +219,8 @@ class SmallPtrSetImplBase : public DebugEpochBase {
219
219
bool contains_imp (const void *Ptr) const {
220
220
if (isSmall ()) {
221
221
// 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;
224
224
for (; APtr != E; ++APtr)
225
225
if (*APtr == Ptr)
226
226
return true ;
@@ -230,7 +230,7 @@ class SmallPtrSetImplBase : public DebugEpochBase {
230
230
return doFind (Ptr) != nullptr ;
231
231
}
232
232
233
- bool isSmall () const { return CurArray == SmallArray ; }
233
+ bool isSmall () const { return IsSmall ; }
234
234
235
235
private:
236
236
std::pair<const void *const *, bool > insert_imp_big (const void *Ptr);
@@ -245,16 +245,19 @@ class SmallPtrSetImplBase : public DebugEpochBase {
245
245
protected:
246
246
// / swap - Swaps the elements of two sets.
247
247
// / 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);
249
250
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);
252
254
253
255
private:
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);
258
261
};
259
262
260
263
// / SmallPtrSetIteratorImpl - This is the common base class shared between all
@@ -415,7 +418,7 @@ class SmallPtrSetImpl : public SmallPtrSetImplBase {
415
418
bool remove_if (UnaryPredicate P) {
416
419
bool Removed = false ;
417
420
if (isSmall ()) {
418
- const void **APtr = SmallArray , **E = SmallArray + NumNonEmpty;
421
+ const void **APtr = CurArray , **E = CurArray + NumNonEmpty;
419
422
while (APtr != E) {
420
423
PtrType Ptr = PtrTraits::getFromVoidPointer (const_cast <void *>(*APtr));
421
424
if (P (Ptr)) {
@@ -540,7 +543,8 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
540
543
SmallPtrSet () : BaseT(SmallStorage, SmallSizePowTwo) {}
541
544
SmallPtrSet (const SmallPtrSet &that) : BaseT(SmallStorage, that) {}
542
545
SmallPtrSet (SmallPtrSet &&that)
543
- : BaseT(SmallStorage, SmallSizePowTwo, std::move(that)) {}
546
+ : BaseT(SmallStorage, SmallSizePowTwo, that.SmallStorage,
547
+ std::move (that)) {}
544
548
545
549
template <typename It>
546
550
SmallPtrSet (It I, It E) : BaseT(SmallStorage, SmallSizePowTwo) {
@@ -555,14 +559,15 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
555
559
SmallPtrSet<PtrType, SmallSize> &
556
560
operator =(const SmallPtrSet<PtrType, SmallSize> &RHS) {
557
561
if (&RHS != this )
558
- this ->CopyFrom ( RHS);
562
+ this ->copyFrom (SmallStorage, RHS);
559
563
return *this ;
560
564
}
561
565
562
566
SmallPtrSet<PtrType, SmallSize> &
563
567
operator =(SmallPtrSet<PtrType, SmallSize> &&RHS) {
564
568
if (&RHS != this )
565
- this ->MoveFrom (SmallSizePowTwo, std::move (RHS));
569
+ this ->moveFrom (SmallStorage, SmallSizePowTwo, RHS.SmallStorage ,
570
+ std::move (RHS));
566
571
return *this ;
567
572
}
568
573
@@ -575,7 +580,7 @@ class SmallPtrSet : public SmallPtrSetImpl<PtrType> {
575
580
576
581
// / swap - Swaps the elements of two sets.
577
582
void swap (SmallPtrSet<PtrType, SmallSize> &RHS) {
578
- SmallPtrSetImplBase::swap (RHS);
583
+ SmallPtrSetImplBase::swap (SmallStorage, RHS. SmallStorage , RHS);
579
584
}
580
585
};
581
586
0 commit comments