summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/FileSystemStatCache.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-11 07:48:23 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-11 07:48:23 +0000
commit3b7793797f773ee0132b38767b104ad80af75229 (patch)
treecf23e1f1775f3baa245e66f82fece41cd860b09c /clang/lib/Basic/FileSystemStatCache.cpp
parent53c3877f94635ed77ccb35cd1dffc3b44e42dff4 (diff)
downloadbcm5719-llvm-3b7793797f773ee0132b38767b104ad80af75229.tar.gz
bcm5719-llvm-3b7793797f773ee0132b38767b104ad80af75229.zip
Extend stat query APIs to explicitly specify if the query is for
a file or directory, allowing just a stat call if a file descriptor is not needed. Doing just 'stat' is faster than 'open/fstat/close'. This has the effect of cutting down system time for validating the input files of a PCH. llvm-svn: 169831
Diffstat (limited to 'clang/lib/Basic/FileSystemStatCache.cpp')
-rw-r--r--clang/lib/Basic/FileSystemStatCache.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/clang/lib/Basic/FileSystemStatCache.cpp b/clang/lib/Basic/FileSystemStatCache.cpp
index 875d397a1da..38c46299018 100644
--- a/clang/lib/Basic/FileSystemStatCache.cpp
+++ b/clang/lib/Basic/FileSystemStatCache.cpp
@@ -34,21 +34,23 @@ void FileSystemStatCache::anchor() { }
/// path, using the cache to accelerate it if possible. This returns true if
/// the path does not exist or false if it exists.
///
-/// If FileDescriptor is non-null, then this lookup should only return success
-/// for files (not directories). If it is null this lookup should only return
+/// If isFile is true, then this lookup should only return success for files
+/// (not directories). If it is false this lookup should only return
/// success for directories (not files). On a successful file lookup, the
/// implementation can optionally fill in FileDescriptor with a valid
/// descriptor and the client guarantees that it will close it.
bool FileSystemStatCache::get(const char *Path, struct stat &StatBuf,
- int *FileDescriptor, FileSystemStatCache *Cache) {
+ bool isFile, int *FileDescriptor,
+ FileSystemStatCache *Cache) {
LookupResult R;
- bool isForDir = FileDescriptor == 0;
+ bool isForDir = !isFile;
// If we have a cache, use it to resolve the stat query.
if (Cache)
- R = Cache->getStat(Path, StatBuf, FileDescriptor);
- else if (isForDir) {
- // If this is a directory and we have no cache, just go to the file system.
+ R = Cache->getStat(Path, StatBuf, isFile, FileDescriptor);
+ else if (isForDir || !FileDescriptor) {
+ // If this is a directory or a file descriptor is not needed and we have
+ // no cache, just go to the file system.
R = ::stat(Path, &StatBuf) != 0 ? CacheMissing : CacheExists;
} else {
// Otherwise, we have to go to the filesystem. We can always just use
@@ -104,8 +106,8 @@ bool FileSystemStatCache::get(const char *Path, struct stat &StatBuf,
MemorizeStatCalls::LookupResult
MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf,
- int *FileDescriptor) {
- LookupResult Result = statChained(Path, StatBuf, FileDescriptor);
+ bool isFile, int *FileDescriptor) {
+ LookupResult Result = statChained(Path, StatBuf, isFile, FileDescriptor);
// 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
OpenPOWER on IntegriCloud