From db001b1276e9681769811f8496f2ddfda2d6062b Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 7 Aug 2025 09:55:10 -0700 Subject: [PATCH] [ADT] Use range-based for loops in StringMap.h (NFC) --- llvm/include/llvm/ADT/StringMap.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h index f839edf031006..0bf062f988f3a 100644 --- a/llvm/include/llvm/ADT/StringMap.h +++ b/llvm/include/llvm/ADT/StringMap.h @@ -89,6 +89,10 @@ class StringMapImpl { /// setup the map as empty. LLVM_ABI void init(unsigned Size); + iterator_range buckets() { + return make_range(TheTable, TheTable + NumBuckets); + } + public: static constexpr uintptr_t TombstoneIntVal = static_cast(-1) @@ -198,8 +202,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap // to default values. This is a copy of clear(), but avoids unnecessary // work not required in the destructor. if (!empty()) { - for (unsigned I = 0, E = NumBuckets; I != E; ++I) { - StringMapEntryBase *Bucket = TheTable[I]; + for (StringMapEntryBase *Bucket : buckets()) { if (Bucket && Bucket != getTombstoneVal()) { static_cast(Bucket)->Destroy(getAllocator()); } @@ -398,8 +401,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap // Zap all values, resetting the keys back to non-present (not tombstone), // which is safe because we're removing all elements. - for (unsigned I = 0, E = NumBuckets; I != E; ++I) { - StringMapEntryBase *&Bucket = TheTable[I]; + for (StringMapEntryBase *&Bucket : buckets()) { if (Bucket && Bucket != getTombstoneVal()) { static_cast(Bucket)->Destroy(getAllocator()); }