Skip to content

Conversation

kazutakahirata
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/158443.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMap.h (+7-3)
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) {

@kazutakahirata kazutakahirata merged commit a5641e4 into llvm:main Sep 14, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants