summaryrefslogtreecommitdiff
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 88a7a1250837..079a4bbfc82f 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -221,12 +221,12 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
// We've not seen this before. Fill it in.
++NumFileCacheMisses;
- auto &NamedFileEnt = *SeenFileInsertResult.first;
- assert(!NamedFileEnt.second && "should be newly-created");
+ auto *NamedFileEnt = &*SeenFileInsertResult.first;
+ assert(!NamedFileEnt->second && "should be newly-created");
// Get the null-terminated file name as stored as the key of the
// SeenFileEntries map.
- StringRef InterndFileName = NamedFileEnt.first();
+ StringRef InterndFileName = NamedFileEnt->first();
// Look up the directory for the file. When looking up something like
// sys/foo.h we'll discover all of the search directories that have a 'sys'
@@ -236,7 +236,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
auto DirInfoOrErr = getDirectoryFromFile(*this, Filename, CacheFailure);
if (!DirInfoOrErr) { // Directory doesn't exist, file can't exist.
if (CacheFailure)
- NamedFileEnt.second = DirInfoOrErr.getError();
+ NamedFileEnt->second = DirInfoOrErr.getError();
else
SeenFileEntries.erase(Filename);
@@ -255,7 +255,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
if (statError) {
// There's no real file at the given path.
if (CacheFailure)
- NamedFileEnt.second = statError;
+ NamedFileEnt->second = statError;
else
SeenFileEntries.erase(Filename);
@@ -268,7 +268,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
// This occurs when one dir is symlinked to another, for example.
FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
- NamedFileEnt.second = &UFE;
+ NamedFileEnt->second = &UFE;
// If the name returned by getStatValue is different than Filename, re-intern
// the name.
@@ -281,7 +281,11 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
// In addition to re-interning the name, construct a redirecting seen file
// entry, that will point to the name the filesystem actually wants to use.
StringRef *Redirect = new (CanonicalNameStorage) StringRef(InterndFileName);
- NamedFileEnt.second = Redirect;
+ auto SeenFileInsertResultIt = SeenFileEntries.find(Filename);
+ assert(SeenFileInsertResultIt != SeenFileEntries.end() &&
+ "unexpected SeenFileEntries cache miss");
+ SeenFileInsertResultIt->second = Redirect;
+ NamedFileEnt = &*SeenFileInsertResultIt;
}
if (UFE.isValid()) { // Already have an entry with this inode, return it.
@@ -544,10 +548,9 @@ void FileManager::GetUniqueIDMapping(
}
StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
- // FIXME: use llvm::sys::fs::canonical() when it gets implemented
- llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known
- = CanonicalDirNames.find(Dir);
- if (Known != CanonicalDirNames.end())
+ llvm::DenseMap<const void *, llvm::StringRef>::iterator Known
+ = CanonicalNames.find(Dir);
+ if (Known != CanonicalNames.end())
return Known->second;
StringRef CanonicalName(Dir->getName());
@@ -556,7 +559,23 @@ StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf))
CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
- CanonicalDirNames.insert({Dir, CanonicalName});
+ CanonicalNames.insert({Dir, CanonicalName});
+ return CanonicalName;
+}
+
+StringRef FileManager::getCanonicalName(const FileEntry *File) {
+ llvm::DenseMap<const void *, llvm::StringRef>::iterator Known
+ = CanonicalNames.find(File);
+ if (Known != CanonicalNames.end())
+ return Known->second;
+
+ StringRef CanonicalName(File->getName());
+
+ SmallString<4096> CanonicalNameBuf;
+ if (!FS->getRealPath(File->getName(), CanonicalNameBuf))
+ CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
+
+ CanonicalNames.insert({File, CanonicalName});
return CanonicalName;
}