[lld] r287296 - [ELF] Use std::for_each() and hoist common code in a lambda.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 17 18:18:05 PST 2016


Author: davide
Date: Thu Nov 17 20:18:04 2016
New Revision: 287296

URL: http://llvm.org/viewvc/llvm-project?rev=287296&view=rev
Log:
[ELF] Use std::for_each() and hoist common code in a lambda.

Modified:
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=287296&r1=287295&r2=287296&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Nov 17 20:18:04 2016
@@ -542,13 +542,11 @@ template <class ELFT> void OutputSection
   ArrayRef<uint8_t> Filler = Script<ELFT>::X->getFiller(this->Name);
   if (!Filler.empty())
     fill(Buf, this->Size, Filler);
-  if (Config->Threads) {
-    parallel_for_each(Sections.begin(), Sections.end(),
-                      [=](InputSection<ELFT> *C) { C->writeTo(Buf); });
-  } else {
-    for (InputSection<ELFT> *C : Sections)
-      C->writeTo(Buf);
-  }
+  auto Fn = [=](InputSection<ELFT> *C) { C->writeTo(Buf); };
+  if (Config->Threads)
+    parallel_for_each(Sections.begin(), Sections.end(), Fn);
+  else
+    std::for_each(Sections.begin(), Sections.end(), Fn);
   // Linker scripts may have BYTE()-family commands with which you
   // can write arbitrary bytes to the output. Process them if any.
   Script<ELFT>::X->writeDataBytes(this->Name, Buf);




More information about the llvm-commits mailing list