Skip to content

[ADT] Use range-based for loops in StringMap.h (NFC) #152641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions llvm/include/llvm/ADT/StringMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class StringMapImpl {
/// setup the map as empty.
LLVM_ABI void init(unsigned Size);

iterator_range<StringMapEntryBase **> buckets() {
return make_range(TheTable, TheTable + NumBuckets);
}

public:
static constexpr uintptr_t TombstoneIntVal =
static_cast<uintptr_t>(-1)
Expand Down Expand Up @@ -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<MapEntryTy *>(Bucket)->Destroy(getAllocator());
}
Expand Down Expand Up @@ -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<MapEntryTy *>(Bucket)->Destroy(getAllocator());
}
Expand Down