[clang] [Basic] Avoid repeated hash lookups (NFC) (PR #111467)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 7 19:44:53 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/111467.diff


1 Files Affected:

- (modified) clang/include/clang/Basic/PlistSupport.h (+4-7) 


``````````diff
diff --git a/clang/include/clang/Basic/PlistSupport.h b/clang/include/clang/Basic/PlistSupport.h
index d52d196019cf84..1814130f1d2cb6 100644
--- a/clang/include/clang/Basic/PlistSupport.h
+++ b/clang/include/clang/Basic/PlistSupport.h
@@ -26,13 +26,10 @@ using FIDMap = llvm::DenseMap<FileID, unsigned>;
 
 inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
                    FileID FID) {
-  FIDMap::iterator I = FIDs.find(FID);
-  if (I != FIDs.end())
-    return I->second;
-  unsigned NewValue = V.size();
-  FIDs[FID] = NewValue;
-  V.push_back(FID);
-  return NewValue;
+  auto [I, Inserted] = FIDs.try_emplace(FID, V.size());
+  if (Inserted)
+    V.push_back(FID);
+  return I->second;
 }
 
 inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,

``````````

</details>


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


More information about the cfe-commits mailing list