@@ -66,7 +66,8 @@ template <typename AllocatorT = MallocAllocator, size_t SlabSize = 4096,
66
66
size_t SizeThreshold = SlabSize, size_t GrowthDelay = 128 >
67
67
class BumpPtrAllocatorImpl
68
68
: public AllocatorBase<BumpPtrAllocatorImpl<AllocatorT, SlabSize,
69
- SizeThreshold, GrowthDelay>> {
69
+ SizeThreshold, GrowthDelay>>,
70
+ private AllocatorT {
70
71
public:
71
72
static_assert (SizeThreshold <= SlabSize,
72
73
" The SizeThreshold must be at most the SlabSize to ensure "
@@ -80,15 +81,15 @@ class BumpPtrAllocatorImpl
80
81
81
82
template <typename T>
82
83
BumpPtrAllocatorImpl (T &&Allocator)
83
- : Allocator (std::forward<T &&>(Allocator)) {}
84
+ : AllocatorT (std::forward<T &&>(Allocator)) {}
84
85
85
86
// Manually implement a move constructor as we must clear the old allocator's
86
87
// slabs as a matter of correctness.
87
88
BumpPtrAllocatorImpl (BumpPtrAllocatorImpl &&Old)
88
- : CurPtr(Old.CurPtr), End(Old.End), Slabs(std::move(Old.Slabs)),
89
+ : AllocatorT(static_cast <AllocatorT &&>(Old)), CurPtr(Old.CurPtr),
90
+ End (Old.End), Slabs(std::move(Old.Slabs)),
89
91
CustomSizedSlabs(std::move(Old.CustomSizedSlabs)),
90
- BytesAllocated(Old.BytesAllocated), RedZoneSize(Old.RedZoneSize),
91
- Allocator(std::move(Old.Allocator)) {
92
+ BytesAllocated(Old.BytesAllocated), RedZoneSize(Old.RedZoneSize) {
92
93
Old.CurPtr = Old.End = nullptr ;
93
94
Old.BytesAllocated = 0 ;
94
95
Old.Slabs .clear ();
@@ -110,7 +111,7 @@ class BumpPtrAllocatorImpl
110
111
RedZoneSize = RHS.RedZoneSize ;
111
112
Slabs = std::move (RHS.Slabs );
112
113
CustomSizedSlabs = std::move (RHS.CustomSizedSlabs );
113
- Allocator = std::move ( RHS. Allocator );
114
+ AllocatorT:: operator =( static_cast <AllocatorT &&>( RHS) );
114
115
115
116
RHS.CurPtr = RHS.End = nullptr ;
116
117
RHS.BytesAllocated = 0 ;
@@ -170,7 +171,8 @@ class BumpPtrAllocatorImpl
170
171
// If Size is really big, allocate a separate slab for it.
171
172
size_t PaddedSize = SizeToAllocate + Alignment.value () - 1 ;
172
173
if (PaddedSize > SizeThreshold) {
173
- void *NewSlab = Allocator.Allocate (PaddedSize, alignof (std::max_align_t ));
174
+ void *NewSlab =
175
+ AllocatorT::Allocate (PaddedSize, alignof (std::max_align_t ));
174
176
// We own the new slab and don't want anyone reading anyting other than
175
177
// pieces returned from this method. So poison the whole slab.
176
178
__asan_poison_memory_region (NewSlab, PaddedSize);
@@ -315,9 +317,6 @@ class BumpPtrAllocatorImpl
315
317
// / a sanitizer.
316
318
size_t RedZoneSize = 1 ;
317
319
318
- // / The allocator instance we use to get slabs of memory.
319
- AllocatorT Allocator;
320
-
321
320
static size_t computeSlabSize (unsigned SlabIdx) {
322
321
// Scale the actual allocated slab size based on the number of slabs
323
322
// allocated. Every GrowthDelay slabs allocated, we double
@@ -333,7 +332,7 @@ class BumpPtrAllocatorImpl
333
332
size_t AllocatedSlabSize = computeSlabSize (Slabs.size ());
334
333
335
334
void *NewSlab =
336
- Allocator. Allocate (AllocatedSlabSize, alignof (std::max_align_t ));
335
+ AllocatorT:: Allocate (AllocatedSlabSize, alignof (std::max_align_t ));
337
336
// We own the new slab and don't want anyone reading anything other than
338
337
// pieces returned from this method. So poison the whole slab.
339
338
__asan_poison_memory_region (NewSlab, AllocatedSlabSize);
@@ -349,7 +348,7 @@ class BumpPtrAllocatorImpl
349
348
for (; I != E; ++I) {
350
349
size_t AllocatedSlabSize =
351
350
computeSlabSize (std::distance (Slabs.begin (), I));
352
- Allocator. Deallocate (*I, AllocatedSlabSize, alignof (std::max_align_t ));
351
+ AllocatorT:: Deallocate (*I, AllocatedSlabSize, alignof (std::max_align_t ));
353
352
}
354
353
}
355
354
@@ -358,7 +357,7 @@ class BumpPtrAllocatorImpl
358
357
for (auto &PtrAndSize : CustomSizedSlabs) {
359
358
void *Ptr = PtrAndSize.first ;
360
359
size_t Size = PtrAndSize.second ;
361
- Allocator. Deallocate (Ptr, Size, alignof (std::max_align_t ));
360
+ AllocatorT:: Deallocate (Ptr, Size, alignof (std::max_align_t ));
362
361
}
363
362
}
364
363
0 commit comments