[llvm] [llvm] Use range-based for loops (NFC) (PR #105861)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 11:14:30 PDT 2024


================
@@ -1808,9 +1808,9 @@ class ModuleSummaryIndex {
   /// the ThinLTO backends.
   TypeIdSummary &getOrInsertTypeIdSummary(StringRef TypeId) {
     auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId));
-    for (auto It = TidIter.first; It != TidIter.second; ++It)
-      if (It->second.first == TypeId)
-        return It->second.second;
+    for (auto &KV : make_range(TidIter))
----------------
ellishg wrote:

[Structured binding](https://en.cppreference.com/w/cpp/language/structured_binding) allows you to name the pair elements directly, which I think help readability (you might know of better names than `Key`/`Value`). I'm not sure if this will work here or in the rest of this PR, but it's worth a try.

```suggestion
    for (auto &[Key, Value] : make_range(TidIter))
```

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


More information about the llvm-commits mailing list