[lld] r248558 - ELF2: Use lambdas instead of named functions.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 20:48:26 PDT 2015


Author: ruiu
Date: Thu Sep 24 22:48:25 2015
New Revision: 248558

URL: http://llvm.org/viewvc/llvm-project?rev=248558&view=rev
Log:
ELF2: Use lambdas instead of named functions.

They are short and used only once, so writing them where they are used
is better.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=248558&r1=248557&r2=248558&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 24 22:48:25 2015
@@ -212,19 +212,6 @@ template <bool Is64Bits> struct DenseMap
 };
 }
 
-template <class ELFT>
-static bool cmpAlign(const DefinedCommon<ELFT> *A,
-                     const DefinedCommon<ELFT> *B) {
-  return A->MaxAlignment > B->MaxAlignment;
-}
-
-template <bool Is64Bits>
-static bool compSec(OutputSectionBase<Is64Bits> *A,
-                    OutputSectionBase<Is64Bits> *B) {
-  // Place SHF_ALLOC sections first.
-  return (A->getFlags() & SHF_ALLOC) && !(B->getFlags() & SHF_ALLOC);
-}
-
 // The reason we have to do this early scan is as follows
 // * To mmap the output file, we need to know the size
 // * For that, we need to know how many dynamic relocs we will have.
@@ -361,7 +348,12 @@ template <class ELFT> void Writer<ELFT>:
   }
 
   // Sort the common symbols by alignment as an heuristic to pack them better.
-  std::stable_sort(CommonSymbols.begin(), CommonSymbols.end(), cmpAlign<ELFT>);
+  std::stable_sort(
+      CommonSymbols.begin(), CommonSymbols.end(),
+      [](const DefinedCommon<ELFT> *A, const DefinedCommon<ELFT> *B) {
+        return A->MaxAlignment > B->MaxAlignment;
+      });
+
   uintX_t Off = BssSec.getSize();
   for (DefinedCommon<ELFT> *C : CommonSymbols) {
     const Elf_Sym &Sym = C->Sym;
@@ -391,8 +383,14 @@ template <class ELFT> void Writer<ELFT>:
   if (!PltSec.empty())
     OutputSections.push_back(&PltSec);
 
-  std::stable_sort(OutputSections.begin(), OutputSections.end(),
-                   compSec<ELFT::Is64Bits>);
+  std::stable_sort(
+      OutputSections.begin(), OutputSections.end(),
+      [](OutputSectionBase<ELFT::Is64Bits> *A,
+         OutputSectionBase<ELFT::Is64Bits> *B) {
+        // Place SHF_ALLOC sections first.
+        return (A->getFlags() & SHF_ALLOC) && !(B->getFlags() & SHF_ALLOC);
+      });
+
   for (unsigned I = 0, N = OutputSections.size(); I < N; ++I)
     OutputSections[I]->setSectionIndex(I + 1);
 }




More information about the llvm-commits mailing list