[lld] r309652 - Binary search to find a relocation.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 21:11:03 PDT 2017


Author: ruiu
Date: Mon Jul 31 21:11:03 2017
New Revision: 309652

URL: http://llvm.org/viewvc/llvm-project?rev=309652&view=rev
Log:
Binary search to find a relocation.

This change makes -gdb-index 40% faster. My test case is self-linking lld.

Differential Revision: https://reviews.llvm.org/D36079

Modified:
    lld/trunk/ELF/GdbIndex.cpp

Modified: lld/trunk/ELF/GdbIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.cpp?rev=309652&r1=309651&r2=309652&view=diff
==============================================================================
--- lld/trunk/ELF/GdbIndex.cpp (original)
+++ lld/trunk/ELF/GdbIndex.cpp Mon Jul 31 21:11:03 2017
@@ -79,11 +79,13 @@ template <class RelTy>
 Optional<RelocAddrEntry>
 LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
                            ArrayRef<RelTy> Rels) const {
-  auto I = llvm::find_if(Rels,
-                         [=](const RelTy &Rel) { return Rel.r_offset == Pos; });
-  if (I == Rels.end())
+  auto It = std::lower_bound(
+      Rels.begin(), Rels.end(), Pos,
+      [](const RelTy &A, uint64_t B) { return A.r_offset < B; });
+  if (It == Rels.end() || It->r_offset != Pos)
     return None;
-  const RelTy &Rel = *I;
+  const RelTy &Rel = *It;
+
   const ObjFile<ELFT> *File = Sec.getFile<ELFT>();
   uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
   const typename ELFT::Sym &Sym = File->getELFSymbols()[SymIndex];




More information about the llvm-commits mailing list