[llvm] [ADT] Add DenseMap::deallocateBuckets (NFC) (PR #158443)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 13 14:47:17 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/158443

This patch adds a small helper function DenseMap::deallocateBuckets
just like SmallDenseMap::deallocateBuckets.

With the new helper function:

  ~DenseMap()
  DenseMap &operator=(DenseMap &&other)

will look identical to their respective SmallDenseMap counterparts,
facilitating further refactoring.


>From 061d0218e5a944ef619a6a4470befd682720aadf Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 13 Sep 2025 13:34:33 -0700
Subject: [PATCH] [ADT] Add DenseMap::deallocateBuckets (NFC)

This patch adds a small helper function DenseMap::deallocateBuckets
just like SmallDenseMap::deallocateBuckets.

With the new helper function:

  ~DenseMap()
  DenseMap &operator=(DenseMap &&other)

will look identical to their respective SmallDenseMap counterparts,
facilitating further refactoring.
---
 llvm/include/llvm/ADT/DenseMap.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 18dd7f30c5616..f076049c55a26 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -738,7 +738,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
 
   ~DenseMap() {
     this->destroyAll();
-    deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
+    deallocateBuckets();
   }
 
   void swap(DenseMap &RHS) {
@@ -758,7 +758,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
 
   DenseMap &operator=(DenseMap &&other) {
     this->destroyAll();
-    deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
+    deallocateBuckets();
     init(0);
     swap(other);
     return *this;
@@ -766,7 +766,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
 
   void copyFrom(const DenseMap &other) {
     this->destroyAll();
-    deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
+    deallocateBuckets();
     if (allocateBuckets(other.NumBuckets)) {
       this->BaseT::copyFrom(other);
     } else {
@@ -827,6 +827,10 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
 
   unsigned getNumBuckets() const { return NumBuckets; }
 
+  void deallocateBuckets() {
+    deallocate_buffer(Buckets, sizeof(BucketT) * NumBuckets, alignof(BucketT));
+  }
+
   bool allocateBuckets(unsigned Num) {
     NumBuckets = Num;
     if (NumBuckets == 0) {



More information about the llvm-commits mailing list