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

llvm-svn: 309652
This commit is contained in:
Rui Ueyama 2017-08-01 04:11:03 +00:00
parent b9417dbd48
commit f974994e15
1 changed files with 6 additions and 4 deletions

View File

@ -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];