[llvm] [ObjectYAML] Avoid repeated hash lookups (NFC) (PR #126187)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 6 22:50:35 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-objectyaml
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/126187.diff
1 Files Affected:
- (modified) llvm/lib/ObjectYAML/DWARFEmitter.cpp (+4-7)
``````````diff
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 421dfe7dfa30efb..ec5e08082b0ca59 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -96,12 +96,11 @@ Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const {
assert(Index < DebugAbbrev.size() &&
"Index should be less than the size of DebugAbbrev array");
- auto It = AbbrevTableContents.find(Index);
- if (It != AbbrevTableContents.cend())
+ auto [It, Inserted] = AbbrevTableContents.try_emplace(Index);
+ if (!Inserted)
return It->second;
- std::string AbbrevTableBuffer;
- raw_string_ostream OS(AbbrevTableBuffer);
+ raw_string_ostream OS(It->second);
uint64_t AbbrevCode = 0;
for (const DWARFYAML::Abbrev &AbbrevDecl : DebugAbbrev[Index].Table) {
@@ -123,9 +122,7 @@ StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const {
// consisting of a 0 byte for the abbreviation code.
OS.write_zeros(1);
- AbbrevTableContents.insert({Index, AbbrevTableBuffer});
-
- return AbbrevTableContents[Index];
+ return It->second;
}
Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/126187
More information about the llvm-commits
mailing list