From 10e286aa8d39fb51a21412850265d9dae74613ee Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 23 Nov 2010 19:19:34 +0000 Subject: rework the stat cache, pulling it out of FileManager.h into its own header and giving it some more structure. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120030 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CacheTokens.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'lib/Frontend/CacheTokens.cpp') diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp index 2defce340f..94bee6b868 100644 --- a/lib/Frontend/CacheTokens.cpp +++ b/lib/Frontend/CacheTokens.cpp @@ -13,11 +13,12 @@ //===----------------------------------------------------------------------===// #include "clang/Frontend/Utils.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" -#include "clang/Basic/SourceManager.h" +#include "clang/Basic/FileSystemStatCache.h" #include "clang/Basic/IdentifierTable.h" -#include "clang/Basic/Diagnostic.h" #include "clang/Basic/OnDiskHashTable.h" +#include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/StringExtras.h" @@ -510,26 +511,31 @@ namespace { /// as input to PTH generation. StatListener populates the PTHWriter's /// file map with stat information for directories as well as negative stats. /// Stat information for files are populated elsewhere. -class StatListener : public StatSysCallCache { +class StatListener : public FileSystemStatCache { PTHMap ± public: StatListener(PTHMap &pm) : PM(pm) {} ~StatListener() {} - int stat(const char *path, struct stat *buf) { - int result = StatSysCallCache::stat(path, buf); - - if (result != 0) // Failed 'stat'. - PM.insert(PTHEntryKeyVariant(path), PTHEntry()); - else if (S_ISDIR(buf->st_mode)) { + LookupResult getStat(const char *Path, struct stat &StatBuf) { + LookupResult Result = FileSystemStatCache::statChained(Path, StatBuf); + + // If the chained cache didn't know anything about the file, do the stat now + // so we can record the result. + if (Result == CacheMiss) + Result = ::stat(Path, &StatBuf) ? CacheHitMissing : CacheHitExists; + + if (Result == CacheHitMissing) // Failed 'stat'. + PM.insert(PTHEntryKeyVariant(Path), PTHEntry()); + else if (S_ISDIR(StatBuf.st_mode)) { // Only cache directories with absolute paths. - if (!llvm::sys::Path(path).isAbsolute()) - return result; + if (!llvm::sys::Path(Path).isAbsolute()) + return Result; - PM.insert(PTHEntryKeyVariant(buf, path), PTHEntry()); + PM.insert(PTHEntryKeyVariant(&StatBuf, Path), PTHEntry()); } - return result; + return Result; } }; } // end anonymous namespace -- cgit v1.2.3-18-g5258