[clang] Optimize Cache Insertion with try_emplace for Reduced Lookups (PR #131402)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 15 02:22:57 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff fbf0276b6a7a7a4508c373cf87fc349569652659 28f6d8b6677e32f45f5fa55c7c73df5a841d7127 --extensions h -- clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index a24ba86dae..08e6a2e678 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -248,15 +248,15 @@ public:
const CachedFileSystemEntry &Entry) {
assert(llvm::sys::path::is_absolute_gnu(Filename));
- auto &[CachedEntry, CachedRealPath] = Cache.try_emplace(
- Filename, &Entry, nullptr).first->getValue();
-
- if (!CachedEntry) {
- assert((!CachedEntry && CachedRealPath) && "entry already present");
- CachedEntry = &Entry;
- }
-
- return *CachedEntry;
+ auto &[CachedEntry, CachedRealPath] =
+ Cache.try_emplace(Filename, &Entry, nullptr).first->getValue();
+
+ if (!CachedEntry) {
+ assert((!CachedEntry && CachedRealPath) && "entry already present");
+ CachedEntry = &Entry;
+ }
+
+ return *CachedEntry;
}
/// Returns real path associated with the filename or nullptr if none is
@@ -273,14 +273,14 @@ public:
insertRealPathForFilename(StringRef Filename,
const CachedRealPath &RealPath) {
assert(llvm::sys::path::is_absolute_gnu(Filename));
- auto &[CachedEntry, CachedRealPath] = Cache.try_emplace(
- Filename, nullptr, &RealPath).first->getValue();
-
+ auto &[CachedEntry, CachedRealPath] =
+ Cache.try_emplace(Filename, nullptr, &RealPath).first->getValue();
+
if (!CachedRealPath) {
assert((!CachedRealPath && CachedEntry) && "real path already present");
CachedRealPath = &RealPath;
}
-
+
return *CachedRealPath;
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/131402
More information about the cfe-commits
mailing list