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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 12 01:55:33 PDT 2024


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

None

>From 5f28ae474a02e00d6d038cd870d1eda76304e83f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 12 Jul 2024 00:56:59 -0700
Subject: [PATCH] [MC] Use range-based for loops (NFC)

---
 llvm/lib/MC/MCELFStreamer.cpp | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index a30a64ba3df5e..38ebaccf3b6ff 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -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)
+    if (Item.Tag == Attribute)
+      return &Item;
   return nullptr;
 }
 
 size_t
 MCELFStreamer::calculateContentSize(SmallVector<AttributeItem, 64> &AttrsVec) {
   size_t Result = 0;
-  for (size_t I = 0; I < AttrsVec.size(); ++I) {
-    AttributeItem Item = AttrsVec[I];
+  for (const AttributeItem &Item : AttrsVec) {
     switch (Item.Type) {
     case AttributeItem::HiddenAttribute:
       break;
@@ -770,8 +769,7 @@ void MCELFStreamer::createAttributesSection(
 
   // Size should have been accounted for already, now
   // emit each field as its type (ULEB or String)
-  for (size_t I = 0; I < AttrsVec.size(); ++I) {
-    AttributeItem Item = AttrsVec[I];
+  for (const AttributeItem &Item : AttrsVec) {
     emitULEB128IntValue(Item.Tag);
     switch (Item.Type) {
     default:



More information about the llvm-commits mailing list