[llvm] [ADT] Use range-based for loops in SparseBitVector.h (NFC) (PR #158408)

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 13 00:08:54 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) llvm/include/llvm/ADT/SparseBitVector.h (+4-7) 


``````````diff
diff --git a/llvm/include/llvm/ADT/SparseBitVector.h b/llvm/include/llvm/ADT/SparseBitVector.h
index 7151af6146e6e..35b3c25db5077 100644
--- a/llvm/include/llvm/ADT/SparseBitVector.h
+++ b/llvm/include/llvm/ADT/SparseBitVector.h
@@ -119,8 +119,8 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
 
   size_type count() const {
     unsigned NumBits = 0;
-    for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
-      NumBits += llvm::popcount(Bits[i]);
+    for (BitWord Bit : Bits)
+      NumBits += llvm::popcount(Bit);
     return NumBits;
   }
 
@@ -799,11 +799,8 @@ class SparseBitVector {
 
   unsigned count() const {
     unsigned BitCount = 0;
-    for (ElementListConstIter Iter = Elements.begin();
-         Iter != Elements.end();
-         ++Iter)
-      BitCount += Iter->count();
-
+    for (const auto &Elem : Elements)
+      BitCount += Elem.count();
     return BitCount;
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/158408


More information about the llvm-commits mailing list