Skip to content

Commit 6abe831

Browse files
committed
switch the implementation to binary search instead
1 parent ab33820 commit 6abe831

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

llvm/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
10-
#include "llvm/ADT/DenseMap.h"
1110
#include "llvm/ADT/SmallVector.h"
1211
#include "llvm/ADT/StringRef.h"
1312
#include "llvm/Support/DataExtractor.h"
@@ -62,14 +61,17 @@ void DWARFGdbIndex::dumpSymbolTable(raw_ostream &OS) const {
6261
SymbolTableOffset, (uint64_t)SymbolTable.size())
6362
<< '\n';
6463

65-
llvm::DenseMap<uint32_t, uint32_t> OffsetToIdMap(ConstantPoolVectors.size());
66-
for (uint32_t Id = 0; Id < ConstantPoolVectors.size(); ++Id)
67-
OffsetToIdMap[ConstantPoolVectors[Id].first] = Id;
68-
6964
const auto FindCuVectorId = [&](uint32_t VecOffset) {
70-
const auto It = OffsetToIdMap.find(VecOffset);
71-
assert(It != OffsetToIdMap.end() && "Invalid symbol table");
72-
return It->second;
65+
// Entries in ConstantPoolVectors are sorted by their offset in constant
66+
// pool, see how ConstantPoolVectors is populated in parseImpl.
67+
const auto *It =
68+
llvm::lower_bound(ConstantPoolVectors, VecOffset,
69+
[](const auto &ConstantPoolEntry, uint32_t Offset) {
70+
return ConstantPoolEntry.first < Offset;
71+
});
72+
assert(It != ConstantPoolVectors.end() && It->first == VecOffset &&
73+
"Invalid symbol table");
74+
return It - ConstantPoolVectors.begin();
7375
};
7476

7577
uint32_t I = -1;

0 commit comments

Comments
 (0)