[llvm] r251024 - Avoid hash lookups when finalizing StringTableBuilder. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 22 08:26:35 PDT 2015
Author: rafael
Date: Thu Oct 22 10:26:35 2015
New Revision: 251024
URL: http://llvm.org/viewvc/llvm-project?rev=251024&view=rev
Log:
Avoid hash lookups when finalizing StringTableBuilder. NFC.
Modified:
llvm/trunk/lib/MC/StringTableBuilder.cpp
Modified: llvm/trunk/lib/MC/StringTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/StringTableBuilder.cpp?rev=251024&r1=251023&r2=251024&view=diff
==============================================================================
--- llvm/trunk/lib/MC/StringTableBuilder.cpp (original)
+++ llvm/trunk/lib/MC/StringTableBuilder.cpp Thu Oct 22 10:26:35 2015
@@ -15,9 +15,10 @@
using namespace llvm;
-static int compareBySuffix(const StringRef *AP, const StringRef *BP) {
- StringRef a = *AP;
- StringRef b = *BP;
+static int compareBySuffix(StringMapEntry<size_t> *const *AP,
+ StringMapEntry<size_t> *const *BP) {
+ StringRef a = (*AP)->first();
+ StringRef b = (*BP)->first();
size_t sizeA = a.size();
size_t sizeB = b.size();
size_t len = std::min(sizeA, sizeB);
@@ -31,11 +32,10 @@ static int compareBySuffix(const StringR
}
void StringTableBuilder::finalize(Kind kind) {
- SmallVector<StringRef, 8> Strings;
+ std::vector<StringMapEntry<size_t> *> Strings;
Strings.reserve(StringIndexMap.size());
-
- for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i)
- Strings.push_back(i->getKey());
+ for (StringMapEntry<size_t> &P : StringIndexMap)
+ Strings.push_back(&P);
array_pod_sort(Strings.begin(), Strings.end(), compareBySuffix);
@@ -52,16 +52,17 @@ void StringTableBuilder::finalize(Kind k
}
StringRef Previous;
- for (StringRef s : Strings) {
+ for (StringMapEntry<size_t> *P : Strings) {
+ StringRef s = P->first();
if (kind == WinCOFF)
assert(s.size() > COFF::NameSize && "Short string in COFF string table!");
if (Previous.endswith(s)) {
- StringIndexMap[s] = StringTable.size() - 1 - s.size();
+ P->second = StringTable.size() - 1 - s.size();
continue;
}
- StringIndexMap[s] = StringTable.size();
+ P->second = StringTable.size();
StringTable += s;
StringTable += '\x00';
Previous = s;
More information about the llvm-commits
mailing list