Skip to content

Conversation

kazutakahirata
Copy link
Contributor

makeIterator and makeConstIterator take a reference to DebugEpochBase,
which is the base class of DenseMapBase. Since both these functions
and their callers are in DenseMapBase, we don't really need to pass
*this.

This patch drops "&Epoch" from these two functions and adjust callers
accordingly.

makeIterator and makeConstIterator take a reference to DebugEpochBase,
which is the base class of DenseMapBase.  Since both these functions
and their callers are in DenseMapBase, we don't really need to pass
*this.

This patch drops "&Epoch" from these two functions and adjust callers
accordingly.
@llvmbot
Copy link
Member

llvmbot commented Aug 30, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

makeIterator and makeConstIterator take a reference to DebugEpochBase,
which is the base class of DenseMapBase. Since both these functions
and their callers are in DenseMapBase, we don't really need to pass
*this.

This patch drops "&Epoch" from these two functions and adjust callers
accordingly.


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMap.h (+16-19)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 4a2da7f630663..e5c424a41d96c 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -81,21 +81,21 @@ class DenseMapBase : public DebugEpochBase {
     if (empty())
       return end();
     if (shouldReverseIterate<KeyT>())
-      return makeIterator(getBucketsEnd() - 1, getBuckets(), *this);
-    return makeIterator(getBuckets(), getBucketsEnd(), *this);
+      return makeIterator(getBucketsEnd() - 1, getBuckets());
+    return makeIterator(getBuckets(), getBucketsEnd());
   }
   inline iterator end() {
-    return makeIterator(getBucketsEnd(), getBucketsEnd(), *this, true);
+    return makeIterator(getBucketsEnd(), getBucketsEnd(), true);
   }
   inline const_iterator begin() const {
     if (empty())
       return end();
     if (shouldReverseIterate<KeyT>())
-      return makeConstIterator(getBucketsEnd() - 1, getBuckets(), *this);
-    return makeConstIterator(getBuckets(), getBucketsEnd(), *this);
+      return makeConstIterator(getBucketsEnd() - 1, getBuckets());
+    return makeConstIterator(getBuckets(), getBucketsEnd());
   }
   inline const_iterator end() const {
-    return makeConstIterator(getBucketsEnd(), getBucketsEnd(), *this, true);
+    return makeConstIterator(getBucketsEnd(), getBucketsEnd(), true);
   }
 
   // Return an iterator to iterate over keys in the map.
@@ -186,7 +186,7 @@ class DenseMapBase : public DebugEpochBase {
     if (BucketT *Bucket = doFind(Val))
       return makeIterator(
           Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
-          *this, true);
+          true);
     return end();
   }
   template <class LookupKeyT>
@@ -194,7 +194,7 @@ class DenseMapBase : public DebugEpochBase {
     if (const BucketT *Bucket = doFind(Val))
       return makeConstIterator(
           Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
-          *this, true);
+          true);
     return end();
   }
 
@@ -485,30 +485,27 @@ class DenseMapBase : public DebugEpochBase {
     return {makeInsertIterator(Bucket), Inserted};
   }
 
-  iterator makeIterator(BucketT *P, BucketT *E, DebugEpochBase &Epoch,
-                        bool NoAdvance = false) {
+  iterator makeIterator(BucketT *P, BucketT *E, bool NoAdvance = false) {
     if (shouldReverseIterate<KeyT>()) {
       BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
-      return iterator(B, E, Epoch, NoAdvance);
+      return iterator(B, E, *this, NoAdvance);
     }
-    return iterator(P, E, Epoch, NoAdvance);
+    return iterator(P, E, *this, NoAdvance);
   }
 
   const_iterator makeConstIterator(const BucketT *P, const BucketT *E,
-                                   const DebugEpochBase &Epoch,
                                    const bool NoAdvance = false) const {
     if (shouldReverseIterate<KeyT>()) {
       const BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
-      return const_iterator(B, E, Epoch, NoAdvance);
+      return const_iterator(B, E, *this, NoAdvance);
     }
-    return const_iterator(P, E, Epoch, NoAdvance);
+    return const_iterator(P, E, *this, NoAdvance);
   }
 
   iterator makeInsertIterator(BucketT *TheBucket) {
-    return makeIterator(TheBucket,
-                        shouldReverseIterate<KeyT>() ? getBuckets()
-                                                     : getBucketsEnd(),
-                        *this, true);
+    return makeIterator(
+        TheBucket,
+        shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(), true);
   }
 
   unsigned getNumEntries() const {

@kazutakahirata
Copy link
Contributor Author

I have a little more comprehensive idea to clean up iterators.

@kazutakahirata kazutakahirata deleted the cleanup_20250830_DenseMap_Epoch branch August 31, 2025 01:29
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.

2 participants