[lld] r311878 - [ELF] - Simplify (use llvm::erase_if). NFC.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 02:28:15 PDT 2017


Author: grimar
Date: Mon Aug 28 02:28:15 2017
New Revision: 311878

URL: http://llvm.org/viewvc/llvm-project?rev=311878&view=rev
Log:
[ELF] - Simplify (use llvm::erase_if). NFC.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=311878&r1=311877&r2=311878&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Aug 28 02:28:15 2017
@@ -642,13 +642,11 @@ void LinkerScript::removeEmptyCommands()
   // clutter the output.
   // We instead remove trivially empty sections. The bfd linker seems even
   // more aggressive at removing them.
-  auto Pos = std::remove_if(Opt.Commands.begin(), Opt.Commands.end(),
-                            [&](BaseCommand *Base) {
-                              if (auto *Sec = dyn_cast<OutputSection>(Base))
-                                return !Sec->Live;
-                              return false;
-                            });
-  Opt.Commands.erase(Pos, Opt.Commands.end());
+  llvm::erase_if(Opt.Commands, [&](BaseCommand *Base) {
+    if (auto *Sec = dyn_cast<OutputSection>(Base))
+      return !Sec->Live;
+    return false;
+  });
 }
 
 static bool isAllSectionDescription(const OutputSection &Cmd) {
@@ -778,10 +776,8 @@ void LinkerScript::allocateHeaders(std::
     Phdrs.erase(It);
   }
 
-  auto PhdrI = llvm::find_if(
-      Phdrs, [](const PhdrEntry *E) { return E->p_type == PT_PHDR; });
-  if (PhdrI != Phdrs.end())
-    Phdrs.erase(PhdrI);
+  llvm::erase_if(Phdrs,
+                 [](const PhdrEntry *E) { return E->p_type == PT_PHDR; });
 }
 
 LinkerScript::AddressState::AddressState(const ScriptConfiguration &Opt) {

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=311878&r1=311877&r2=311878&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 28 02:28:15 2017
@@ -123,7 +123,7 @@ template <class ELFT> static bool needsI
 template <class ELFT> void elf::writeResult() { Writer<ELFT>().run(); }
 
 template <class ELFT> void Writer<ELFT>::removeEmptyPTLoad() {
-  auto I = llvm::remove_if(Phdrs, [&](const PhdrEntry *P) {
+  llvm::erase_if(Phdrs, [&](const PhdrEntry *P) {
     if (P->p_type != PT_LOAD)
       return false;
     if (!P->First)
@@ -131,7 +131,6 @@ template <class ELFT> void Writer<ELFT>:
     uint64_t Size = P->Last->Addr + P->Last->Size - P->First->Addr;
     return Size == 0;
   });
-  Phdrs.erase(I, Phdrs.end());
 }
 
 template <class ELFT> static void combineEhFrameSections() {
@@ -1141,13 +1140,11 @@ static void removeUnusedSyntheticSection
     // output.
     if (OS->Commands.empty()) {
       // Also remove script commands matching the output section.
-      auto &Cmds = Script->Opt.Commands;
-      auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd2) {
-        if (auto *Sec = dyn_cast<OutputSection>(Cmd2))
+      llvm::erase_if(Script->Opt.Commands, [&](BaseCommand *Cmd) {
+        if (auto *Sec = dyn_cast<OutputSection>(Cmd))
           return Sec == OS;
         return false;
       });
-      Cmds.erase(I, Cmds.end());
     }
   }
 }




More information about the llvm-commits mailing list