[clang] [Basic] Avoid repeated hash lookups (NFC) (PR #111467)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 19:44:18 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/111467
None
>From fd6654f61025f4dc5b38a02d5c4ec3b52fe2c726 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 7 Oct 2024 07:04:14 -0700
Subject: [PATCH] [Basic] Avoid repeated hash lookups (NFC)
---
clang/include/clang/Basic/PlistSupport.h | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
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,
More information about the cfe-commits
mailing list