[ELF] Use std::for_each() and hoist common code in a lambda.
authorDavide Italiano <davide@freebsd.org>
Fri, 18 Nov 2016 02:18:04 +0000 (02:18 +0000)
committerDavide Italiano <davide@freebsd.org>
Fri, 18 Nov 2016 02:18:04 +0000 (02:18 +0000)
llvm-svn: 287296

lld/ELF/OutputSections.cpp

index 4bf9529..6034db1 100644 (file)
@@ -542,13 +542,11 @@ template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
   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);