Skip to content

Commit e015f66

Browse files
committed
Avoid hash lookups when finalizing StringTableBuilder. NFC.
llvm-svn: 251024
1 parent 0169a45 commit e015f66

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

llvm/lib/MC/StringTableBuilder.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
using namespace llvm;
1717

18-
static int compareBySuffix(const StringRef *AP, const StringRef *BP) {
19-
StringRef a = *AP;
20-
StringRef b = *BP;
18+
static int compareBySuffix(StringMapEntry<size_t> *const *AP,
19+
StringMapEntry<size_t> *const *BP) {
20+
StringRef a = (*AP)->first();
21+
StringRef b = (*BP)->first();
2122
size_t sizeA = a.size();
2223
size_t sizeB = b.size();
2324
size_t len = std::min(sizeA, sizeB);
@@ -31,11 +32,10 @@ static int compareBySuffix(const StringRef *AP, const StringRef *BP) {
3132
}
3233

3334
void StringTableBuilder::finalize(Kind kind) {
34-
SmallVector<StringRef, 8> Strings;
35+
std::vector<StringMapEntry<size_t> *> Strings;
3536
Strings.reserve(StringIndexMap.size());
36-
37-
for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i)
38-
Strings.push_back(i->getKey());
37+
for (StringMapEntry<size_t> &P : StringIndexMap)
38+
Strings.push_back(&P);
3939

4040
array_pod_sort(Strings.begin(), Strings.end(), compareBySuffix);
4141

@@ -52,16 +52,17 @@ void StringTableBuilder::finalize(Kind kind) {
5252
}
5353

5454
StringRef Previous;
55-
for (StringRef s : Strings) {
55+
for (StringMapEntry<size_t> *P : Strings) {
56+
StringRef s = P->first();
5657
if (kind == WinCOFF)
5758
assert(s.size() > COFF::NameSize && "Short string in COFF string table!");
5859

5960
if (Previous.endswith(s)) {
60-
StringIndexMap[s] = StringTable.size() - 1 - s.size();
61+
P->second = StringTable.size() - 1 - s.size();
6162
continue;
6263
}
6364

64-
StringIndexMap[s] = StringTable.size();
65+
P->second = StringTable.size();
6566
StringTable += s;
6667
StringTable += '\x00';
6768
Previous = s;

0 commit comments

Comments
 (0)