Skip to content

Commit 30b0a9e

Browse files
[ADT] Use range-based for loops in StringMap.h (NFC) (#152641)
1 parent e64224a commit 30b0a9e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvm/include/llvm/ADT/StringMap.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class StringMapImpl {
8989
/// setup the map as empty.
9090
LLVM_ABI void init(unsigned Size);
9191

92+
iterator_range<StringMapEntryBase **> buckets() {
93+
return make_range(TheTable, TheTable + NumBuckets);
94+
}
95+
9296
public:
9397
static constexpr uintptr_t TombstoneIntVal =
9498
static_cast<uintptr_t>(-1)
@@ -198,8 +202,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
198202
// to default values. This is a copy of clear(), but avoids unnecessary
199203
// work not required in the destructor.
200204
if (!empty()) {
201-
for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
202-
StringMapEntryBase *Bucket = TheTable[I];
205+
for (StringMapEntryBase *Bucket : buckets()) {
203206
if (Bucket && Bucket != getTombstoneVal()) {
204207
static_cast<MapEntryTy *>(Bucket)->Destroy(getAllocator());
205208
}
@@ -398,8 +401,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
398401

399402
// Zap all values, resetting the keys back to non-present (not tombstone),
400403
// which is safe because we're removing all elements.
401-
for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
402-
StringMapEntryBase *&Bucket = TheTable[I];
404+
for (StringMapEntryBase *&Bucket : buckets()) {
403405
if (Bucket && Bucket != getTombstoneVal()) {
404406
static_cast<MapEntryTy *>(Bucket)->Destroy(getAllocator());
405407
}

0 commit comments

Comments
 (0)