[ELF] - Replace parallelForEach with ranged form.
Makes code a bit more convinent to write/read.
Differential revision: https://reviews.llvm.org/D36089
llvm-svn: 310040
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 5519d16..301062c 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2218,15 +2218,14 @@
 void elf::decompressAndMergeSections() {
   // splitIntoPieces needs to be called on each MergeInputSection before calling
   // finalizeContents(). Do that first.
-  parallelForEach(InputSections.begin(), InputSections.end(),
-                  [](InputSectionBase *S) {
-                    if (!S->Live)
-                      return;
-                    if (Decompressor::isCompressedELFSection(S->Flags, S->Name))
-                      S->uncompress();
-                    if (auto *MS = dyn_cast<MergeInputSection>(S))
-                      MS->splitIntoPieces();
-                  });
+  parallelForEach(InputSections, [](InputSectionBase *S) {
+    if (!S->Live)
+      return;
+    if (Decompressor::isCompressedELFSection(S->Flags, S->Name))
+      S->uncompress();
+    if (auto *MS = dyn_cast<MergeInputSection>(S))
+      MS->splitIntoPieces();
+  });
 
   std::vector<MergeSyntheticSection *> MergeSections;
   for (InputSectionBase *&S : InputSections) {
diff --git a/lld/ELF/Threads.h b/lld/ELF/Threads.h
index 9feb868..924aca0 100644
--- a/lld/ELF/Threads.h
+++ b/lld/ELF/Threads.h
@@ -67,12 +67,11 @@
 namespace lld {
 namespace elf {
 
-template <class IterTy, class FuncTy>
-void parallelForEach(IterTy Begin, IterTy End, FuncTy Fn) {
+template <typename R, class FuncTy> void parallelForEach(R &&Range, FuncTy Fn) {
   if (Config->Threads)
-    for_each(llvm::parallel::par, Begin, End, Fn);
+    for_each(llvm::parallel::par, std::begin(Range), std::end(Range), Fn);
   else
-    for_each(llvm::parallel::seq, Begin, End, Fn);
+    for_each(llvm::parallel::seq, std::begin(Range), std::end(Range), Fn);
 }
 
 inline void parallelForEachN(size_t Begin, size_t End,
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0ea28d8..186f4fa 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -199,7 +199,7 @@
   // If -compressed-debug-sections is specified, we need to compress
   // .debug_* sections. Do it right now because it changes the size of
   // output sections.
-  parallelForEach(OutputSections.begin(), OutputSections.end(),
+  parallelForEach(OutputSections,
                   [](OutputSection *Sec) { Sec->maybeCompress<ELFT>(); });
 
   Script->assignAddresses();