summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-01-26 00:55:12 +0000
committerDouglas Gregor <dgregor@apple.com>2013-01-26 00:55:12 +0000
commite00c8b205e24122ce3cb6169dd4e85c16c2fdadd (patch)
treeb7b20eca5a8cd95c9c0385a8a05cfcdcc605efce /clang/lib/Basic/FileManager.cpp
parentd0c842d7a496b15d2b771c9ee605c1570ba49793 (diff)
downloadbcm5719-llvm-e00c8b205e24122ce3cb6169dd4e85c16c2fdadd.tar.gz
bcm5719-llvm-e00c8b205e24122ce3cb6169dd4e85c16c2fdadd.zip
Since we're stuck with realpath for the header <-> module mapping,
factor the realpath calls into FileManager::getCanonicalName() so we can cache the results of this epically slow operation. 5% speedup on my modules test, and realpath drops out of the profile. llvm-svn: 173542
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 3a7bdefdaff..19f170e25ab 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -40,6 +40,11 @@
#define S_ISFIFO(x) (0)
#endif
#endif
+#if defined(LLVM_ON_UNIX)
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
+#endif
using namespace clang;
// FIXME: Enhance libsystem to support inode and other fields.
@@ -620,6 +625,29 @@ void FileManager::modifyFileEntry(FileEntry *File,
File->ModTime = ModificationTime;
}
+StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
+ // FIXME: use llvm::sys::fs::canonical() when it gets implemented
+#ifdef LLVM_ON_UNIX
+ llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known
+ = CanonicalDirNames.find(Dir);
+ if (Known != CanonicalDirNames.end())
+ return Known->second;
+
+ StringRef CanonicalName(Dir->getName());
+ char CanonicalNameBuf[PATH_MAX];
+ if (realpath(Dir->getName(), CanonicalNameBuf)) {
+ unsigned Len = strlen(CanonicalNameBuf);
+ char *Mem = static_cast<char *>(CanonicalNameStorage.Allocate(Len, 1));
+ memcpy(Mem, CanonicalNameBuf, Len);
+ CanonicalName = StringRef(Mem, Len);
+ }
+
+ CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));
+ return CanonicalName;
+#else
+ return StringRef(Dir->getName());
+#endif
+}
void FileManager::PrintStats() const {
llvm::errs() << "\n*** File Manager Stats:\n";
OpenPOWER on IntegriCloud