Skip to content

Commit 7379100

Browse files
[Support] Consolidate the two implementations of Recycler::clear (NFC) (#165081)
This patch consolidates the two implementations of Recycler::clear with "if constexpr" for simplicity.
1 parent d461244 commit 7379100

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

llvm/include/llvm/Support/Recycler.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Support/Compiler.h"
2020
#include "llvm/Support/ErrorHandling.h"
2121
#include <cassert>
22+
#include <type_traits>
2223

2324
namespace llvm {
2425

@@ -72,19 +73,19 @@ class Recycler {
7273
/// deleted; calling clear is one way to ensure this.
7374
template<class AllocatorType>
7475
void clear(AllocatorType &Allocator) {
75-
while (FreeList) {
76-
T *t = reinterpret_cast<T *>(pop_val());
77-
Allocator.Deallocate(t, Size, Align);
76+
if constexpr (std::is_same_v<std::decay_t<AllocatorType>,
77+
BumpPtrAllocator>) {
78+
// For BumpPtrAllocator, Deallocate is a no-op, so just drop the free
79+
// list.
80+
FreeList = nullptr;
81+
} else {
82+
while (FreeList) {
83+
T *t = reinterpret_cast<T *>(pop_val());
84+
Allocator.Deallocate(t, Size, Align);
85+
}
7886
}
7987
}
8088

81-
/// Special case for BumpPtrAllocator which has an empty Deallocate()
82-
/// function.
83-
///
84-
/// There is no need to traverse the free list, pulling all the objects into
85-
/// cache.
86-
void clear(BumpPtrAllocator &) { FreeList = nullptr; }
87-
8889
template<class SubClass, class AllocatorType>
8990
SubClass *Allocate(AllocatorType &Allocator) {
9091
static_assert(alignof(SubClass) <= Align,

0 commit comments

Comments
 (0)