[llvm] 0f47627 - [ObjectYAML] Avoid repeated hash lookups (NFC) (#111938)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 09:00:19 PDT 2024


Author: Kazu Hirata
Date: 2024-10-11T09:00:15-07:00
New Revision: 0f476277d52b3d31739fe8a1b06791f1747e152d

URL: https://github.com/llvm/llvm-project/commit/0f476277d52b3d31739fe8a1b06791f1747e152d
DIFF: https://github.com/llvm/llvm-project/commit/0f476277d52b3d31739fe8a1b06791f1747e152d.diff

LOG: [ObjectYAML] Avoid repeated hash lookups (NFC) (#111938)

Added: 
    

Modified: 
    llvm/lib/ObjectYAML/COFFEmitter.cpp

Removed: 
    


################################################################################
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