[PATCH] D125483: [BOLT][NFC] Use refs for loop variables to avoid copies

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 12 10:56:08 PDT 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Addresses warnings when built with Apple Clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125483

Files:
  bolt/lib/Core/BinaryFunction.cpp
  bolt/lib/Profile/DataReader.cpp
  bolt/lib/Rewrite/BoltDiff.cpp


Index: bolt/lib/Rewrite/BoltDiff.cpp
===================================================================
--- bolt/lib/Rewrite/BoltDiff.cpp
+++ bolt/lib/Rewrite/BoltDiff.cpp
@@ -219,7 +219,7 @@
       const BinaryFunction &Function = BFI.second;
       const double Score = getNormalizedScore(Function, RI1);
       LargestBin1.insert(std::make_pair<>(Score, &Function));
-      for (const StringRef Name : Function.getNames()) {
+      for (const StringRef &Name : Function.getNames()) {
         if (Optional<StringRef> OptionalLTOName = getLTOCommonName(Name))
           LTOName = *OptionalLTOName;
         NameLookup[Name] = &Function;
@@ -239,7 +239,7 @@
       const BinaryFunction &Function = BFI.second;
       const double Score = getNormalizedScore(Function, RI2);
       LargestBin2.insert(std::make_pair<>(Score, &Function));
-      for (const StringRef Name : Function.getNames()) {
+      for (const StringRef &Name : Function.getNames()) {
         if (Optional<StringRef> OptionalLTOName = getLTOCommonName(Name))
           LTOName = *OptionalLTOName;
       }
@@ -261,7 +261,7 @@
       const BinaryFunction &Function2 = BFI2.second;
       StringRef LTOName;
       bool Match = false;
-      for (const StringRef Name : Function2.getNames()) {
+      for (const StringRef &Name : Function2.getNames()) {
         auto Iter = NameLookup.find(Name);
         if (Optional<StringRef> OptionalLTOName = getLTOCommonName(Name))
           LTOName = *OptionalLTOName;
Index: bolt/lib/Profile/DataReader.cpp
===================================================================
--- bolt/lib/Profile/DataReader.cpp
+++ bolt/lib/Profile/DataReader.cpp
@@ -56,7 +56,7 @@
 
 /// Return true if the function name can change across compilations.
 bool hasVolatileName(const BinaryFunction &BF) {
-  for (const StringRef Name : BF.getNames())
+  for (const StringRef &Name : BF.getNames())
     if (getLTOCommonName(Name))
       return true;
 
Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -419,7 +419,7 @@
   if (AllNames.size() > 1) {
     OS << "\n  All names   : ";
     const char *Sep = "";
-    for (const StringRef Name : AllNames) {
+    for (const StringRef &Name : AllNames) {
       OS << Sep << Name;
       Sep = "\n                ";
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125483.429015.patch
Type: text/x-patch
Size: 2401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220512/a4590588/attachment.bin>


More information about the llvm-commits mailing list