[clang] [CodeGen] Avoid repeated hash lookups (NFC) (PR #107759)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 8 08:09:21 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/107759

None

>From 98280f2c6c2d1e3b6b0566f3c77649e00fe75da9 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 8 Sep 2024 07:43:18 -0700
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)

---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 67a9caf8b4ec4b..07015834bc84f3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2595,12 +2595,7 @@ void CoverageMappingModuleGen::emit() {
 }
 
 unsigned CoverageMappingModuleGen::getFileID(FileEntryRef File) {
-  auto It = FileEntries.find(File);
-  if (It != FileEntries.end())
-    return It->second;
-  unsigned FileID = FileEntries.size() + 1;
-  FileEntries.insert(std::make_pair(File, FileID));
-  return FileID;
+  return FileEntries.try_emplace(File, FileEntries.size() + 1).first->second;
 }
 
 void CoverageMappingGen::emitCounterMapping(const Decl *D,



More information about the cfe-commits mailing list