[DWARF] Simplify DWARFDebugAranges::findAddress

The current lower_bound approach has to check two iterators pos and pos-1.
Changing it to upper_bound allows us to check one iterator (similar to
DWARFUnitVector::getUnitFor*).

llvm-svn: 357834
This commit is contained in:
Fangrui Song 2019-04-06 09:12:53 +00:00
parent cb300f1243
commit 4be8629e49
2 changed files with 6 additions and 19 deletions

View File

@ -49,10 +49,6 @@ private:
return -1ULL;
}
bool containsAddress(uint64_t Address) const {
return LowPC <= Address && Address < HighPC();
}
bool operator<(const Range &other) const {
return LowPC < other.LowPC;
}

View File

@ -114,20 +114,11 @@ void DWARFDebugAranges::construct() {
}
uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const {
if (!Aranges.empty()) {
Range range(Address);
RangeCollIterator begin = Aranges.begin();
RangeCollIterator end = Aranges.end();
RangeCollIterator pos =
std::lower_bound(begin, end, range);
if (pos != end && pos->containsAddress(Address)) {
return pos->CUOffset;
} else if (pos != begin) {
--pos;
if (pos->containsAddress(Address))
return pos->CUOffset;
}
}
RangeCollIterator It =
llvm::upper_bound(Aranges, Address, [](uint64_t LHS, Range RHS) {
return LHS < RHS.HighPC();
});
if (It != Aranges.end() && It->LowPC <= Address)
return It->CUOffset;
return -1U;
}