[lld] e205445 - [ELF] StringTableSection: Use DenseMap<CachedHashStringRef> to avoid redundant hash computation
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 16 21:02:14 PST 2022
Author: Fangrui Song
Date: 2022-01-16T21:02:05-08:00
New Revision: e20544543478b259eb09fa0a253d4fb1a5525d9e
URL: https://github.com/llvm/llvm-project/commit/e20544543478b259eb09fa0a253d4fb1a5525d9e
DIFF: https://github.com/llvm/llvm-project/commit/e20544543478b259eb09fa0a253d4fb1a5525d9e.diff
LOG: [ELF] StringTableSection: Use DenseMap<CachedHashStringRef> to avoid redundant hash computation
5~6% speedup when linking clang and chrome.
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index aef6434dca799..9944877acf6c7 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1239,7 +1239,7 @@ StringTableSection::StringTableSection(StringRef name, bool dynamic)
// them with some other string that happens to be the same.
unsigned StringTableSection::addString(StringRef s, bool hashIt) {
if (hashIt) {
- auto r = stringMap.insert(std::make_pair(s, this->size));
+ auto r = stringMap.try_emplace(CachedHashStringRef(s), size);
if (!r.second)
return r.first->second;
}
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 3090cf1aae147..6f8453288a8eb 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -421,7 +421,7 @@ class StringTableSection final : public SyntheticSection {
uint64_t size = 0;
- llvm::DenseMap<StringRef, unsigned> stringMap;
+ llvm::DenseMap<llvm::CachedHashStringRef, unsigned> stringMap;
SmallVector<StringRef, 0> strings;
};
More information about the llvm-commits
mailing list