virtual ~FileSystemStatCache() {}
enum LookupResult {
- CacheHitExists, //< We know the file exists and its cached stat data.
- CacheHitMissing, //< We know that the file doesn't exist.
- CacheMiss //< We don't know anything about the file.
+ CacheExists, //< We know the file exists and its cached stat data.
+ CacheMissing //< We know that the file doesn't exist.
};
/// FileSystemStatCache::get - Get the 'stat' information for the specified
/// the path does not exist or false if it exists.
static bool get(const char *Path, struct stat &StatBuf,
FileSystemStatCache *Cache) {
- LookupResult R = CacheMiss;
-
if (Cache)
- R = Cache->getStat(Path, StatBuf);
+ return Cache->getStat(Path, StatBuf) == CacheMissing;
- if (R == FileSystemStatCache::CacheMiss)
- return ::stat(Path, &StatBuf);
- return R == FileSystemStatCache::CacheHitMissing;
+ return ::stat(Path, &StatBuf) != 0;
}
/// \brief Sets the next stat call cache in the chain of stat caches.
if (FileSystemStatCache *Next = getNextStatCache())
return Next->getStat(Path, StatBuf);
- return CacheMiss;
+ // If we hit the end of the list of stat caches to try, just compute and
+ // return it without a cache.
+ return get(Path, StatBuf, 0) ? CacheMissing : CacheExists;
}
};
MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf) {
LookupResult Result = 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;
-
// Do not cache failed stats, it is easy to construct common inconsistent
// situations if we do, and they are not important for PCH performance (which
// currently only needs the stats to construct the initial FileManager
// entries).
- if (Result == CacheHitMissing)
+ if (Result == CacheMissing)
return Result;
// Cache file 'stat' results and directories with absolutely paths.
~StatListener() {}
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'.
+ LookupResult Result = statChained(Path, StatBuf);
+
+ if (Result == CacheMissing) // Failed 'stat'.
PM.insert(PTHEntryKeyVariant(Path), PTHEntry());
else if (S_ISDIR(StatBuf.st_mode)) {
// Only cache directories with absolute paths.
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/MemoryBuffer.h"
-#include <sys/stat.h>
using namespace clang;
using namespace clang::io;
const PTHStatData &Data = *I;
if (!Data.hasStat)
- return CacheHitMissing;
+ return CacheMissing;
StatBuf.st_ino = Data.ino;
StatBuf.st_dev = Data.dev;
StatBuf.st_mtime = Data.mtime;
StatBuf.st_mode = Data.mode;
StatBuf.st_size = Data.size;
- return CacheHitExists;
+ return CacheExists;
}
};
} // end anonymous namespace
StatBuf.st_mtime = Data.mtime;
StatBuf.st_mode = Data.mode;
StatBuf.st_size = Data.size;
- return CacheHitExists;
+ return CacheExists;
}
};
} // end anonymous namespace