blob: 6457414df98da7c7cfff5d333bc3039e1fc7903e [file] [log] [blame]
Chris Lattner10e286a2010-11-23 19:19:34 +00001//===--- FileSystemStatCache.cpp - Caching for 'stat' calls ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the FileSystemStatCache interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/FileSystemStatCache.h"
15#include "llvm/System/Path.h"
16using namespace clang;
17
Chris Lattner72f61302010-11-23 20:07:39 +000018#if defined(_MSC_VER)
19#define S_ISDIR(s) (_S_IFDIR & s)
20#endif
21
Chris Lattner10e286a2010-11-23 19:19:34 +000022MemorizeStatCalls::LookupResult
23MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf) {
24 LookupResult Result = statChained(Path, StatBuf);
25
Chris Lattner10e286a2010-11-23 19:19:34 +000026 // Do not cache failed stats, it is easy to construct common inconsistent
27 // situations if we do, and they are not important for PCH performance (which
28 // currently only needs the stats to construct the initial FileManager
29 // entries).
Chris Lattnerd6f61112010-11-23 20:05:15 +000030 if (Result == CacheMissing)
Chris Lattner10e286a2010-11-23 19:19:34 +000031 return Result;
32
33 // Cache file 'stat' results and directories with absolutely paths.
34 if (!S_ISDIR(StatBuf.st_mode) || llvm::sys::Path(Path).isAbsolute())
Chris Lattner74e976b2010-11-23 19:28:12 +000035 StatCalls[Path] = StatBuf;
Chris Lattner10e286a2010-11-23 19:19:34 +000036
37 return Result;
38}