[clang] [llvm] [clang][deps] Cache `VFS::getRealPath()` (PR #68645)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 11 09:46:02 PDT 2024


================
@@ -226,9 +247,28 @@ class DependencyScanningFilesystemLocalCache {
   insertEntryForFilename(StringRef Filename,
                          const CachedFileSystemEntry &Entry) {
     assert(llvm::sys::path::is_absolute_gnu(Filename));
-    const auto *InsertedEntry = Cache.insert({Filename, &Entry}).first->second;
-    assert(InsertedEntry == &Entry && "entry already present");
-    return *InsertedEntry;
+    assert(Cache[Filename].first == nullptr && "entry already present");
+    Cache[Filename].first = &Entry;
+    return Entry;
----------------
benlangmuir wrote:

Nit: I think the original way this was written is slightly better, because in a no-asserts build if this is ever hit, it returns the entry that's actually in the map and in an asserts build it is cheaper to only lookup in the map once instead of twice. I would just keep the old way but insert a pair(&Entry, nullptr)

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


More information about the cfe-commits mailing list