[lld] r276137 - [ELF] - Refactor of LinkerScript<ELFT>::getPhdrIndicesForSection

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 09:43:03 PDT 2016


Author: grimar
Date: Wed Jul 20 11:43:03 2016
New Revision: 276137

URL: http://llvm.org/viewvc/llvm-project?rev=276137&view=rev
Log:
[ELF] - Refactor of LinkerScript<ELFT>::getPhdrIndicesForSection

Previously it was harder to read and also has a error:
command kind was not checked.

Differential revision: https://reviews.llvm.org/D22574

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=276137&r1=276136&r2=276137&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jul 20 11:43:03 2016
@@ -450,23 +450,23 @@ template <class ELFT> bool LinkerScript<
 template <class ELFT>
 std::vector<size_t>
 LinkerScript<ELFT>::getPhdrIndicesForSection(StringRef Name) {
-  std::vector<size_t> Indices;
-  auto ItSect = std::find_if(
-      Opt.Commands.begin(), Opt.Commands.end(),
-      [Name](const SectionsCommand &Cmd) { return Cmd.Name == Name; });
-  if (ItSect != Opt.Commands.end()) {
-    SectionsCommand &SecCmd = (*ItSect);
-    for (StringRef PhdrName : SecCmd.Phdrs) {
-      auto ItPhdr = std::find_if(
-          Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(),
-          [PhdrName](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; });
+  for (SectionsCommand &Cmd : Opt.Commands) {
+    if (Cmd.Kind != SectionKind || Cmd.Name != Name)
+      continue;
+
+    std::vector<size_t> Indices;
+    for (StringRef PhdrName : Cmd.Phdrs) {
+      auto ItPhdr =
+          std::find_if(Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(),
+                       [&](PhdrsCommand &Cmd) { return Cmd.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;
   }
-  return Indices;
+  return {};
 }
 
 class elf::ScriptParser : public ScriptParserBase {




More information about the llvm-commits mailing list