Split getPhdrsIndices. NFC.
llvm-svn: 276717
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 5d601dd..785a3f6 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -405,21 +405,26 @@
     if (!Cmd || Cmd->Name != SectionName)
       continue;
 
-    std::vector<size_t> Indices;
-    for (StringRef PhdrName : Cmd->Phdrs) {
-      auto ItPhdr =
-          std::find_if(Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(),
-                       [&](PhdrsCommand &P) { return P.Name == PhdrName; });
-      if (ItPhdr == Opt.PhdrsCommands.rend())
-        error("section header '" + PhdrName + "' is not listed in PHDRS");
-      else
-        Indices.push_back(std::distance(ItPhdr, Opt.PhdrsCommands.rend()) - 1);
-    }
-    return Indices;
+    std::vector<size_t> Ret;
+    for (StringRef PhdrName : Cmd->Phdrs)
+      Ret.push_back(getPhdrIndex(PhdrName));
+    return Ret;
   }
   return {};
 }
 
+template <class ELFT>
+size_t LinkerScript<ELFT>::getPhdrIndex(StringRef PhdrName) {
+  size_t I = 0;
+  for (PhdrsCommand &Cmd : Opt.PhdrsCommands) {
+    if (Cmd.Name == PhdrName)
+      return I;
+    ++I;
+  }
+  error("section header '" + PhdrName + "' is not listed in PHDRS");
+  return 0;
+}
+
 class elf::ScriptParser : public ScriptParserBase {
   typedef void (ScriptParser::*Handler)();
 
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index ade95ce..c64e7f7 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -144,6 +144,7 @@
 
   int getSectionIndex(StringRef Name);
   std::vector<size_t> getPhdrIndices(StringRef SectionName);
+  size_t getPhdrIndex(StringRef PhdrName);
   void dispatchAssignment(SymbolAssignment *Cmd);
 
   uintX_t Dot;