From d8c87ba110374acb5fb1d520f2ee666a96feba96 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 10 Sep 2025 20:30:25 -0700 Subject: [PATCH] [Support] Consolidate the two implementations of Recycler::clear (NFC) This patch consolidates the two implementations of Recycler::clear with "if constexpr" for simplicity. --- llvm/include/llvm/Support/Recycler.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/Support/Recycler.h b/llvm/include/llvm/Support/Recycler.h index b51c58678e653..6502a70dbf89c 100644 --- a/llvm/include/llvm/Support/Recycler.h +++ b/llvm/include/llvm/Support/Recycler.h @@ -19,6 +19,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include +#include namespace llvm { @@ -72,19 +73,19 @@ class Recycler { /// deleted; calling clear is one way to ensure this. template void clear(AllocatorType &Allocator) { - while (FreeList) { - T *t = reinterpret_cast(pop_val()); - Allocator.Deallocate(t, Size, Align); + if constexpr (std::is_same_v, + BumpPtrAllocator>) { + // For BumpPtrAllocator, Deallocate is a no-op, so just drop the free + // list. + FreeList = nullptr; + } else { + while (FreeList) { + T *t = reinterpret_cast(pop_val()); + Allocator.Deallocate(t, Size, Align); + } } } - /// Special case for BumpPtrAllocator which has an empty Deallocate() - /// function. - /// - /// There is no need to traverse the free list, pulling all the objects into - /// cache. - void clear(BumpPtrAllocator &) { FreeList = nullptr; } - template SubClass *Allocate(AllocatorType &Allocator) { static_assert(alignof(SubClass) <= Align,