[llvm] [ObjectYAML] Avoid repeated hash lookups (NFC) (PR #111938)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 20:41:10 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/111938
None
>From 97e216a4bd3321162008a584d1de8d728f546ef8 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 10 Oct 2024 08:30:34 -0700
Subject: [PATCH] [ObjectYAML] Avoid repeated hash lookups (NFC)
---
llvm/lib/ObjectYAML/COFFEmitter.cpp | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/ObjectYAML/COFFEmitter.cpp b/llvm/lib/ObjectYAML/COFFEmitter.cpp
index bb46de4c6f57f4..3811376adebd26 100644
--- a/llvm/lib/ObjectYAML/COFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/COFFEmitter.cpp
@@ -125,15 +125,12 @@ struct COFFParser {
}
unsigned getStringIndex(StringRef Str) {
- StringMap<unsigned>::iterator i = StringTableMap.find(Str);
- if (i == StringTableMap.end()) {
- unsigned Index = StringTable.size();
+ auto [It, Inserted] = StringTableMap.try_emplace(Str, StringTable.size());
+ if (Inserted) {
StringTable.append(Str.begin(), Str.end());
StringTable.push_back(0);
- StringTableMap[Str] = Index;
- return Index;
}
- return i->second;
+ return It->second;
}
COFFYAML::Object &Obj;
More information about the llvm-commits
mailing list