aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2025-08-08 07:44:44 -0700
committerGitHub <noreply@github.com>2025-08-08 07:44:44 -0700
commit30b0a9ec19620abb951f5ca31330b17da1e3ffcf (patch)
treef4ff31b5ece256666234c1f9bace5d592ef08b12
parente64224a224a9891d01ad6eec84921bca1c1f0441 (diff)
downloadllvm-30b0a9ec19620abb951f5ca31330b17da1e3ffcf.zip
llvm-30b0a9ec19620abb951f5ca31330b17da1e3ffcf.tar.gz
llvm-30b0a9ec19620abb951f5ca31330b17da1e3ffcf.tar.bz2
[ADT] Use range-based for loops in StringMap.h (NFC) (#152641)
-rw-r--r--llvm/include/llvm/ADT/StringMap.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h
index f839edf..0bf062f 100644
--- a/llvm/include/llvm/ADT/StringMap.h
+++ b/llvm/include/llvm/ADT/StringMap.h
@@ -89,6 +89,10 @@ protected:
/// 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)
@@ -198,8 +202,7 @@ public:
// 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());
}
@@ -398,8 +401,7 @@ public:
// 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());
}