[lld] r281329 - Refactor duplicated code. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 06:00:06 PDT 2016


Author: rafael
Date: Tue Sep 13 08:00:06 2016
New Revision: 281329

URL: http://llvm.org/viewvc/llvm-project?rev=281329&view=rev
Log:
Refactor duplicated code. NFC.

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=281329&r1=281328&r2=281329&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Sep 13 08:00:06 2016
@@ -216,6 +216,15 @@ template <class ELFT> void LinkerScript<
 
 template <class ELFT>
 void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
+  auto AddSec = [&](InputSectionBase<ELFT> *Sec, StringRef Name) {
+    OutputSectionBase<ELFT> *OutSec;
+    bool IsNew;
+    std::tie(OutSec, IsNew) = Factory.create(Sec, Name);
+    if (IsNew)
+      OutputSections->push_back(OutSec);
+    return OutSec;
+  };
+
   for (const std::unique_ptr<BaseCommand> &Base1 : Opt.Commands) {
     if (auto *Cmd = dyn_cast<SymbolAssignment>(Base1.get())) {
       if (shouldDefine<ELFT>(Cmd))
@@ -235,12 +244,7 @@ void LinkerScript<ELFT>::createSections(
         continue;
 
       for (InputSectionBase<ELFT> *Sec : V) {
-        OutputSectionBase<ELFT> *OutSec;
-        bool IsNew;
-        std::tie(OutSec, IsNew) = Factory.create(Sec, Cmd->Name);
-        if (IsNew)
-          OutputSections->push_back(OutSec);
-
+        OutputSectionBase<ELFT> *OutSec = AddSec(Sec, Cmd->Name);
         uint32_t Subalign = Cmd->SubalignExpr ? Cmd->SubalignExpr(0) : 0;
 
         if (Subalign)
@@ -256,11 +260,7 @@ void LinkerScript<ELFT>::createSections(
     for (InputSectionBase<ELFT> *S : F->getSections()) {
       if (isDiscarded(S) || S->OutSec)
         continue;
-      OutputSectionBase<ELFT> *OutSec;
-      bool IsNew;
-      std::tie(OutSec, IsNew) = Factory.create(S, getOutputSectionName(S));
-      if (IsNew)
-        OutputSections->push_back(OutSec);
+      OutputSectionBase<ELFT> *OutSec = AddSec(S, getOutputSectionName(S));
       OutSec->addSection(S);
     }
   }




More information about the llvm-commits mailing list