@@ -156,9 +156,11 @@ class DependencyScanningFilesystemSharedCache {
156
156
// / The mutex that needs to be locked before mutation of any member.
157
157
mutable std::mutex CacheLock;
158
158
159
- // / Map from filenames to cached entries.
160
- llvm::StringMap<const CachedFileSystemEntry *, llvm::BumpPtrAllocator>
161
- EntriesByFilename;
159
+ // / Map from filenames to cached entries and real paths.
160
+ llvm::StringMap<
161
+ std::pair<const CachedFileSystemEntry *, const CachedRealPath *>,
162
+ llvm::BumpPtrAllocator>
163
+ CacheByFilename;
162
164
163
165
// / Map from unique IDs to cached entries.
164
166
llvm::DenseMap<llvm::sys::fs::UniqueID, const CachedFileSystemEntry *>
@@ -170,9 +172,6 @@ class DependencyScanningFilesystemSharedCache {
170
172
// / The backing storage for cached contents.
171
173
llvm::SpecificBumpPtrAllocator<CachedFileContents> ContentsStorage;
172
174
173
- // / Map from filenames to cached real paths.
174
- llvm::StringMap<const CachedRealPath *> RealPathsByFilename;
175
-
176
175
// / The backing storage for cached real paths.
177
176
llvm::SpecificBumpPtrAllocator<CachedRealPath> RealPathStorage;
178
177
@@ -229,16 +228,17 @@ class DependencyScanningFilesystemSharedCache {
229
228
// / This class is a local cache, that caches the 'stat' and 'open' calls to the
230
229
// / underlying real file system.
231
230
class DependencyScanningFilesystemLocalCache {
232
- llvm::StringMap<const CachedFileSystemEntry *, llvm::BumpPtrAllocator> Cache;
233
-
234
- llvm::StringMap<const CachedRealPath *, llvm::BumpPtrAllocator> RealPathCache;
231
+ llvm::StringMap<
232
+ std::pair<const CachedFileSystemEntry *, const CachedRealPath *>,
233
+ llvm::BumpPtrAllocator>
234
+ Cache;
235
235
236
236
public:
237
237
// / Returns entry associated with the filename or nullptr if none is found.
238
238
const CachedFileSystemEntry *findEntryByFilename (StringRef Filename) const {
239
239
assert (llvm::sys::path::is_absolute_gnu (Filename));
240
240
auto It = Cache.find (Filename);
241
- return It == Cache.end () ? nullptr : It->getValue ();
241
+ return It == Cache.end () ? nullptr : It->getValue (). first ;
242
242
}
243
243
244
244
// / Associates the given entry with the filename and returns the given entry
@@ -247,17 +247,17 @@ class DependencyScanningFilesystemLocalCache {
247
247
insertEntryForFilename (StringRef Filename,
248
248
const CachedFileSystemEntry &Entry) {
249
249
assert (llvm::sys::path::is_absolute_gnu (Filename));
250
- const auto *InsertedEntry = Cache. insert ({Filename, &Entry}). first -> second ;
251
- assert (InsertedEntry == &Entry && " entry already present " ) ;
252
- return *InsertedEntry ;
250
+ assert (Cache[Filename]. first == nullptr && " entry already present " ) ;
251
+ Cache[Filename]. first = &Entry;
252
+ return Entry ;
253
253
}
254
254
255
255
// / Returns real path associated with the filename or nullptr if none is
256
256
// / found.
257
257
const CachedRealPath *findRealPathByFilename (StringRef Filename) const {
258
258
assert (llvm::sys::path::is_absolute_gnu (Filename));
259
- auto It = RealPathCache .find (Filename);
260
- return It == RealPathCache .end () ? nullptr : It->getValue ();
259
+ auto It = Cache .find (Filename);
260
+ return It == Cache .end () ? nullptr : It->getValue (). second ;
261
261
}
262
262
263
263
// / Associates the given real path with the filename and returns the given
@@ -266,10 +266,9 @@ class DependencyScanningFilesystemLocalCache {
266
266
insertRealPathForFilename (StringRef Filename,
267
267
const CachedRealPath &RealPath) {
268
268
assert (llvm::sys::path::is_absolute_gnu (Filename));
269
- const auto *InsertedRealPath =
270
- RealPathCache.insert ({Filename, &RealPath}).first ->second ;
271
- assert (InsertedRealPath == &RealPath && " entry already present" );
272
- return *InsertedRealPath;
269
+ assert (Cache[Filename].second == nullptr && " entry already present" );
270
+ Cache[Filename].second = &RealPath;
271
+ return RealPath;
273
272
}
274
273
};
275
274
0 commit comments