[llvm] 7379100 - [Support] Consolidate the two implementations of Recycler::clear (NFC) (#165081)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 25 06:23:39 PDT 2025
Author: Kazu Hirata
Date: 2025-10-25T06:23:35-07:00
New Revision: 7379100be637eeb72d732d8f174a3b01d22532e3
URL: https://github.com/llvm/llvm-project/commit/7379100be637eeb72d732d8f174a3b01d22532e3
DIFF: https://github.com/llvm/llvm-project/commit/7379100be637eeb72d732d8f174a3b01d22532e3.diff
LOG: [Support] Consolidate the two implementations of Recycler::clear (NFC) (#165081)
This patch consolidates the two implementations of Recycler::clear
with "if constexpr" for simplicity.
Added:
Modified:
llvm/include/llvm/Support/Recycler.h
Removed:
################################################################################
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 <cassert>
+#include <type_traits>
namespace llvm {
@@ -72,19 +73,19 @@ class Recycler {
/// deleted; calling clear is one way to ensure this.
template<class AllocatorType>
void clear(AllocatorType &Allocator) {
- while (FreeList) {
- T *t = reinterpret_cast<T *>(pop_val());
- Allocator.Deallocate(t, Size, Align);
+ if constexpr (std::is_same_v<std::decay_t<AllocatorType>,
+ BumpPtrAllocator>) {
+ // For BumpPtrAllocator, Deallocate is a no-op, so just drop the free
+ // list.
+ FreeList = nullptr;
+ } else {
+ while (FreeList) {
+ T *t = reinterpret_cast<T *>(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<class SubClass, class AllocatorType>
SubClass *Allocate(AllocatorType &Allocator) {
static_assert(alignof(SubClass) <= Align,
More information about the llvm-commits
mailing list