[clang] [llvm] [clang][deps] Cache `VFS::getRealPath()` (PR #68645)
Jan Svoboda via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 12:52:14 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;
----------------
jansvoboda11 wrote:
The complication is that the cache entry may now already exist, but will only have the real path populated. I guess we can get close to the existing behavior with something like this:
```
auto [It, Inserted] = Cache.insert({Filename, {&Entry, nullptr}});
auto &[CachedEntry, CachedRealPath] = It->getValue();
if (!Inserted) {
// The file is already present in the local cache. If we got here, it only
// contains the real path. Let's make sure the entry is populated too.
assert((!CachedEntry && CachedRealPath) && "entry already present");
CachedEntry = &Entry;
}
return *CachedEntry;
```
https://github.com/llvm/llvm-project/pull/68645
More information about the llvm-commits
mailing list