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 | c504683237defa32b27bf25ea51e6cae8d1ba31b (patch) | |
tree | 085759627adcb81591ae8ce3f22c33b2b86b18df /clang/lib/Basic/FileManager.cpp | |
parent | 01910a50c4ea3fdec7b6a216861764fb28751cec (diff) | |
download | bcm5719-llvm-c504683237defa32b27bf25ea51e6cae8d1ba31b.tar.gz bcm5719-llvm-c504683237defa32b27bf25ea51e6cae8d1ba31b.zip |
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%.
llvm-svn: 70223
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 2cd140d95ed..cc25d330515 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/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; +} |