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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 12 11:37:17 PDT 2024


================
@@ -699,17 +699,16 @@ void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue,
 
 MCELFStreamer::AttributeItem *
 MCELFStreamer::getAttributeItem(unsigned Attribute) {
-  for (size_t I = 0; I < Contents.size(); ++I)
-    if (Contents[I].Tag == Attribute)
-      return &Contents[I];
+  for (AttributeItem &Item : Contents)
----------------
kazutakahirata wrote:

Thank you for the review!  We could reduce the line count by one, but the simple "for" loop might be more readable here:

```
  auto It = llvm::find_if(
      Contents, [&](AttributeItem &Item) { return Item.Tag == Attribute; });
  return It != Contents.end() ? &*It : nullptr;
```


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


More information about the llvm-commits mailing list