diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-27 18:38:38 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-27 18:38:38 +0000 |
commit | 4fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57 (patch) | |
tree | ab4ae9d7fb8680b1c9633cc71c00fea57210b705 /lib/Basic/FileManager.cpp | |
parent | 8e03444e924665d4d90f5cfc0624c815256e0309 (diff) |
Implement caching of stat() calls for precompiled headers, which is
essentially the same thing we do with pretokenized headers. stat()
caching improves performance of the Cocoa-prefixed "Hello, World" by
45%.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70223 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/FileManager.cpp')
-rw-r--r-- | lib/Basic/FileManager.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 2cd140d95e..cc25d33051 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -19,6 +19,7 @@ #include "clang/Basic/FileManager.h" #include "llvm/ADT/SmallString.h" +#include "llvm/System/Path.h" #include "llvm/Support/Streams.h" #include "llvm/Config/config.h" using namespace clang; @@ -282,3 +283,20 @@ void FileManager::PrintStats() const { //llvm::cerr << PagesMapped << BytesOfPagesMapped << FSLookups; } + +int MemorizeStatCalls::stat(const char *path, struct stat *buf) { + int result = ::stat(path, buf); + + if (result != 0) { + // Cache failed 'stat' results. + struct stat empty; + StatCalls[path] = StatResult(result, empty); + } + else if (!S_ISDIR(buf->st_mode) || llvm::sys::Path(path).isAbsolute()) { + // Cache file 'stat' results and directories with absolutely + // paths. + StatCalls[path] = StatResult(result, *buf); + } + + return result; +} |