[llvm] [TargetParser] Use StringRef::consume_front (NFC) (PR #147202)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 6 10:57:41 PDT 2025


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

While we are at it, this patch switches to a range-based for loop.


>From 1c182a9e3d97a4518892b73142d4d74fab30b873 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 5 Jul 2025 10:59:16 -0700
Subject: [PATCH] [TargetParser] Use StringRef::consume_front (NFC)

While we are at it, this patch switches to a range-based for loop.
---
 llvm/lib/TargetParser/Host.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 5957e1befe2da..e668d69a133d3 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -180,13 +180,13 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) {
   StringRef Implementer;
   StringRef Hardware;
   StringRef Part;
-  for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
-    if (Lines[I].starts_with("CPU implementer"))
-      Implementer = Lines[I].substr(15).ltrim("\t :");
-    if (Lines[I].starts_with("Hardware"))
-      Hardware = Lines[I].substr(8).ltrim("\t :");
-    if (Lines[I].starts_with("CPU part"))
-      Part = Lines[I].substr(8).ltrim("\t :");
+  for (StringRef Line : Lines) {
+    if (Line.consume_front("CPU implementer"))
+      Implementer = Line.ltrim("\t :");
+    else if (Line.consume_front("Hardware"))
+      Hardware = Line.ltrim("\t :");
+    else if (Line.consume_front("CPU part"))
+      Part = Line.ltrim("\t :");
   }
 
   if (Implementer == "0x41") { // ARM Ltd.



More information about the llvm-commits mailing list