[lld] r354052 - Remove a comparator from header and instead use lambdas for simplicity. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 14 11:21:10 PST 2019


Author: ruiu
Date: Thu Feb 14 11:21:10 2019
New Revision: 354052

URL: http://llvm.org/viewvc/llvm-project?rev=354052&view=rev
Log:
Remove a comparator from header and instead use lambdas for simplicity. NFC.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Relocations.h

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=354052&r1=354051&r2=354052&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Feb 14 11:21:10 2019
@@ -557,10 +557,16 @@ static Relocation *getRISCVPCRelHi20(con
 
   // Relocations are sorted by offset, so we can use std::equal_range to do
   // binary search.
-  auto Range = std::equal_range(IS->Relocations.begin(), IS->Relocations.end(),
-                                D->Value, RelocationOffsetComparator{});
-  for (auto It = std::get<0>(Range); It != std::get<1>(Range); ++It)
-    if (isRelExprOneOf<R_PC>(It->Expr))
+  Relocation R;
+  R.Offset = D->Value;
+  auto Range =
+      std::equal_range(IS->Relocations.begin(), IS->Relocations.end(), R,
+                       [](const Relocation &LHS, const Relocation &RHS) {
+                         return LHS.Offset < RHS.Offset;
+                       });
+
+  for (auto It = Range.first; It != Range.second; ++It)
+    if (It->Expr == R_PC)
       return &*It;
 
   error("R_RISCV_PCREL_LO12 relocation points to " + IS->getObjMsg(D->Value) +

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=354052&r1=354051&r2=354052&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Feb 14 11:21:10 2019
@@ -1196,7 +1196,9 @@ static void scanRelocs(InputSectionBase
   // Sort relocations by offset to binary search for R_RISCV_PCREL_HI20
   if (Config->EMachine == EM_RISCV)
     std::stable_sort(Sec.Relocations.begin(), Sec.Relocations.end(),
-                     RelocationOffsetComparator{});
+                     [](const Relocation &LHS, const Relocation &RHS) {
+                       return LHS.Offset < RHS.Offset;
+                     });
 }
 
 template <class ELFT> void elf::scanRelocations(InputSectionBase &S) {

Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=354052&r1=354051&r2=354052&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Thu Feb 14 11:21:10 2019
@@ -134,21 +134,6 @@ struct Relocation {
   Symbol *Sym;
 };
 
-struct RelocationOffsetComparator {
-  bool operator()(const Relocation &Lhs, const Relocation &Rhs) {
-    return Lhs.Offset < Rhs.Offset;
-  }
-
-  // For std::lower_bound, std::upper_bound, std::equal_range.
-  bool operator()(const Relocation &Rel, uint64_t Val) {
-    return Rel.Offset < Val;
-  }
-
-  bool operator()(uint64_t Val, const Relocation &Rel) {
-    return Val < Rel.Offset;
-  }
-};
-
 template <class ELFT> void scanRelocations(InputSectionBase &);
 
 void addIRelativeRelocs();




More information about the llvm-commits mailing list