1226efd35SChris Lattner //===--- FileSystemStatCache.cpp - Caching for 'stat' calls ---------------===// 2226efd35SChris Lattner // 3226efd35SChris Lattner // The LLVM Compiler Infrastructure 4226efd35SChris Lattner // 5226efd35SChris Lattner // This file is distributed under the University of Illinois Open Source 6226efd35SChris Lattner // License. See LICENSE.TXT for details. 7226efd35SChris Lattner // 8226efd35SChris Lattner //===----------------------------------------------------------------------===// 9226efd35SChris Lattner // 10226efd35SChris Lattner // This file defines the FileSystemStatCache interface. 11226efd35SChris Lattner // 12226efd35SChris Lattner //===----------------------------------------------------------------------===// 13226efd35SChris Lattner 14226efd35SChris Lattner #include "clang/Basic/FileSystemStatCache.h" 15226efd35SChris Lattner #include "llvm/System/Path.h" 16226efd35SChris Lattner using namespace clang; 17226efd35SChris Lattner 18226efd35SChris Lattner MemorizeStatCalls::LookupResult 19226efd35SChris Lattner MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf) { 20226efd35SChris Lattner LookupResult Result = statChained(Path, StatBuf); 21226efd35SChris Lattner 22226efd35SChris Lattner // If the chained cache didn't know anything about the file, do the stat now 23226efd35SChris Lattner // so we can record the result. 24226efd35SChris Lattner if (Result == CacheMiss) 25226efd35SChris Lattner Result = ::stat(Path, &StatBuf) ? CacheHitMissing : CacheHitExists; 26226efd35SChris Lattner 27226efd35SChris Lattner 28226efd35SChris Lattner // Do not cache failed stats, it is easy to construct common inconsistent 29226efd35SChris Lattner // situations if we do, and they are not important for PCH performance (which 30226efd35SChris Lattner // currently only needs the stats to construct the initial FileManager 31226efd35SChris Lattner // entries). 32226efd35SChris Lattner if (Result == CacheHitMissing) 33226efd35SChris Lattner return Result; 34226efd35SChris Lattner 35226efd35SChris Lattner // Cache file 'stat' results and directories with absolutely paths. 36226efd35SChris Lattner if (!S_ISDIR(StatBuf.st_mode) || llvm::sys::Path(Path).isAbsolute()) 37*2a6fa47bSChris Lattner StatCalls[Path] = StatBuf; 38226efd35SChris Lattner 39226efd35SChris Lattner return Result; 40226efd35SChris Lattner } 41