@@ -235,30 +235,27 @@ struct RoundUpToPowerOfTwo {
235
235
};
236
236
237
237
238
- // / SmallPtrSet - This class implements a set which is optimized for holding
239
- // / SmallSize or less elements. This internally rounds up SmallSize to the next
240
- // / power of two if it is not already a power of two. See the comments above
241
- // / SmallPtrSetImplBase for details of the algorithm.
242
- template <class PtrType , unsigned SmallSize>
243
- class SmallPtrSet : public SmallPtrSetImplBase {
244
- // Make sure that SmallSize is a power of two, round up if not.
245
- enum { SmallSizePowTwo = RoundUpToPowerOfTwo<SmallSize>::Val };
246
- // / SmallStorage - Fixed size storage used in 'small mode'.
247
- const void *SmallStorage[SmallSizePowTwo];
238
+ // / \brief A templated base class for \c SmallPtrSet which provides the
239
+ // / typesafe interface that is common across all small sizes.
240
+ // /
241
+ // / This is particularly useful for passing around between interface boundaries
242
+ // / to avoid encoding a particular small size in the interface boundary.
243
+ template <typename PtrType>
244
+ class SmallPtrSetImpl : public SmallPtrSetImplBase {
248
245
typedef PointerLikeTypeTraits<PtrType> PtrTraits;
249
- public:
250
- SmallPtrSet () : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo) {}
251
- SmallPtrSet (const SmallPtrSet &that) : SmallPtrSetImplBase(SmallStorage, that) {}
246
+ protected:
247
+ // Constructors that forward to the base.
248
+ SmallPtrSetImpl (const void **SmallStorage, const SmallPtrSetImpl &that)
249
+ : SmallPtrSetImplBase(SmallStorage, that) {}
252
250
#if LLVM_HAS_RVALUE_REFERENCES
253
- SmallPtrSet (SmallPtrSet &&that)
254
- : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo, std::move(that)) {}
251
+ SmallPtrSetImpl (const void **SmallStorage, unsigned SmallSize,
252
+ SmallPtrSetImpl &&that)
253
+ : SmallPtrSetImplBase(SmallStorage, SmallSize, std::move(that)) {}
255
254
#endif
255
+ explicit SmallPtrSetImpl (const void **SmallStorage, unsigned SmallSize)
256
+ : SmallPtrSetImplBase(SmallStorage, SmallSize) {}
256
257
257
- template <typename It>
258
- SmallPtrSet (It I, It E) : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo) {
259
- insert (I, E);
260
- }
261
-
258
+ public:
262
259
// / insert - This returns true if the pointer was new to the set, false if it
263
260
// / was already in the set.
264
261
bool insert (PtrType Ptr ) {
@@ -290,19 +287,45 @@ class SmallPtrSet : public SmallPtrSetImplBase {
290
287
inline iterator end () const {
291
288
return iterator (CurArray+CurArraySize, CurArray+CurArraySize);
292
289
}
290
+ };
291
+
292
+ // / SmallPtrSet - This class implements a set which is optimized for holding
293
+ // / SmallSize or less elements. This internally rounds up SmallSize to the next
294
+ // / power of two if it is not already a power of two. See the comments above
295
+ // / SmallPtrSetImplBase for details of the algorithm.
296
+ template <class PtrType , unsigned SmallSize>
297
+ class SmallPtrSet : public SmallPtrSetImpl <PtrType> {
298
+ typedef SmallPtrSetImpl<PtrType> BaseT;
299
+
300
+ // Make sure that SmallSize is a power of two, round up if not.
301
+ enum { SmallSizePowTwo = RoundUpToPowerOfTwo<SmallSize>::Val };
302
+ // / SmallStorage - Fixed size storage used in 'small mode'.
303
+ const void *SmallStorage[SmallSizePowTwo];
304
+ public:
305
+ SmallPtrSet () : BaseT(SmallStorage, SmallSizePowTwo) {}
306
+ SmallPtrSet (const SmallPtrSet &that) : BaseT(SmallStorage, that) {}
307
+ #if LLVM_HAS_RVALUE_REFERENCES
308
+ SmallPtrSet (SmallPtrSet &&that)
309
+ : BaseT(SmallStorage, SmallSizePowTwo, std::move(that)) {}
310
+ #endif
311
+
312
+ template <typename It>
313
+ SmallPtrSet (It I, It E) : BaseT(SmallStorage, SmallSizePowTwo) {
314
+ this ->insert (I, E);
315
+ }
293
316
294
317
SmallPtrSet<PtrType, SmallSize> &
295
318
operator =(const SmallPtrSet<PtrType, SmallSize> &RHS) {
296
319
if (&RHS != this )
297
- CopyFrom (RHS);
320
+ this -> CopyFrom (RHS);
298
321
return *this ;
299
322
}
300
323
301
324
#if LLVM_HAS_RVALUE_REFERENCES
302
325
SmallPtrSet<PtrType, SmallSize>&
303
326
operator =(SmallPtrSet<PtrType, SmallSize> &&RHS) {
304
327
if (&RHS != this )
305
- MoveFrom (SmallSizePowTwo, std::move (RHS));
328
+ this -> MoveFrom (SmallSizePowTwo, std::move (RHS));
306
329
return *this ;
307
330
}
308
331
#endif
0 commit comments