[llvm] [DWARFLinker] Avoid repeated hash lookups (NFC) (PR #109604)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 07:33:53 PDT 2024


================
@@ -287,12 +287,12 @@ uint32_t TypeUnit::addFileNameIntoLinetable(StringEntry *Dir,
   }
 
   uint32_t FileIdx = 0;
-  FilenamesMapTy::iterator FileEntry = FileNamesMap.find({FileName, DirIdx});
-  if (FileEntry == FileNamesMap.end()) {
+  auto [FileEntry, Inserted] = FileNamesMap.try_emplace({FileName, DirIdx});
+  if (Inserted) {
     // We currently do not support more than UINT32_MAX files.
     assert(LineTable.Prologue.FileNames.size() < UINT32_MAX);
     FileIdx = LineTable.Prologue.FileNames.size();
-    FileNamesMap.insert({{FileName, DirIdx}, FileIdx});
+    FileEntry->second = FileIdx;
----------------
kazutakahirata wrote:

I just posted https://github.com/llvm/llvm-project/pull/109670 as a follow-up.

https://github.com/llvm/llvm-project/pull/109604


More information about the llvm-commits mailing list