From 1183c6f920bc348a614ac486f7bea660aeedc114 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Oct 2015 15:26:35 +0000 Subject: [PATCH] Avoid hash lookups when finalizing StringTableBuilder. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251024 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/StringTableBuilder.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/MC/StringTableBuilder.cpp b/lib/MC/StringTableBuilder.cpp index 86e54471794..e4c3aa22717 100644 --- a/lib/MC/StringTableBuilder.cpp +++ b/lib/MC/StringTableBuilder.cpp @@ -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 *const *AP, + StringMapEntry *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 StringRef *AP, const StringRef *BP) { } void StringTableBuilder::finalize(Kind kind) { - SmallVector Strings; + std::vector *> Strings; Strings.reserve(StringIndexMap.size()); - - for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i) - Strings.push_back(i->getKey()); + for (StringMapEntry &P : StringIndexMap) + Strings.push_back(&P); array_pod_sort(Strings.begin(), Strings.end(), compareBySuffix); @@ -52,16 +52,17 @@ void StringTableBuilder::finalize(Kind kind) { } StringRef Previous; - for (StringRef s : Strings) { + for (StringMapEntry *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; -- 2.34.1