/// execution of the front end.
class MemorizeStatCalls : public FileSystemStatCache {
public:
- /// \brief The result of a stat() call.
- ///
- /// The first member is the result of calling stat(). If stat()
- /// found something, the second member is a copy of the stat
- /// structure.
- typedef std::pair<int, struct stat> StatResult;
+ /// \brief The set of stat() calls that have been seen.
+ llvm::StringMap<struct stat, llvm::BumpPtrAllocator> StatCalls;
- /// \brief The set of stat() calls that have been
- llvm::StringMap<StatResult, llvm::BumpPtrAllocator> StatCalls;
-
- typedef llvm::StringMap<StatResult, llvm::BumpPtrAllocator>::const_iterator
+ typedef llvm::StringMap<struct stat, llvm::BumpPtrAllocator>::const_iterator
iterator;
iterator begin() const { return StatCalls.begin(); }
// Cache file 'stat' results and directories with absolutely paths.
if (!S_ISDIR(StatBuf.st_mode) || llvm::sys::Path(Path).isAbsolute())
- StatCalls[Path] = StatResult(Result, StatBuf);
+ StatCalls[Path] = StatBuf;
return Result;
}
class ASTStatData {
public:
- const bool hasStat;
const ino_t ino;
const dev_t dev;
const mode_t mode;
const off_t size;
ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s)
- : hasStat(true), ino(i), dev(d), mode(mo), mtime(m), size(s) {}
-
- ASTStatData()
- : hasStat(false), ino(0), dev(0), mode(0), mtime(0), size(0) {}
+ : ino(i), dev(d), mode(mo), mtime(m), size(s) {}
};
class ASTStatLookupTrait {
unsigned /*DataLen*/) {
using namespace clang::io;
- if (*d++ == 1)
- return data_type();
-
ino_t ino = (ino_t) ReadUnalignedLE32(d);
dev_t dev = (dev_t) ReadUnalignedLE32(d);
mode_t mode = (mode_t) ReadUnalignedLE16(d);
unsigned &NumStatHits, &NumStatMisses;
public:
- ASTStatCache(const unsigned char *Buckets,
- const unsigned char *Base,
- unsigned &NumStatHits,
- unsigned &NumStatMisses)
+ ASTStatCache(const unsigned char *Buckets, const unsigned char *Base,
+ unsigned &NumStatHits, unsigned &NumStatMisses)
: Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) {
Cache = CacheTy::Create(Buckets, Base);
}
++NumStatHits;
ASTStatData Data = *I;
- if (!Data.hasStat)
- return CacheHitMissing;
-
StatBuf.st_ino = Data.ino;
StatBuf.st_dev = Data.dev;
StatBuf.st_mtime = Data.mtime;
typedef const char * key_type;
typedef key_type key_type_ref;
- typedef std::pair<int, struct stat> data_type;
- typedef const data_type& data_type_ref;
+ typedef struct stat data_type;
+ typedef const data_type &data_type_ref;
static unsigned ComputeHash(const char *path) {
return llvm::HashString(path);
data_type_ref Data) {
unsigned StrLen = strlen(path);
clang::io::Emit16(Out, StrLen);
- unsigned DataLen = 1; // result value
- if (Data.first == 0)
- DataLen += 4 + 4 + 2 + 8 + 8;
+ unsigned DataLen = 4 + 4 + 2 + 8 + 8;
clang::io::Emit8(Out, DataLen);
return std::make_pair(StrLen + 1, DataLen);
}
Out.write(path, KeyLen);
}
- void EmitData(llvm::raw_ostream& Out, key_type_ref,
+ void EmitData(llvm::raw_ostream &Out, key_type_ref,
data_type_ref Data, unsigned DataLen) {
using namespace clang::io;
uint64_t Start = Out.tell(); (void)Start;
- // Result of stat()
- Emit8(Out, Data.first? 1 : 0);
-
- if (Data.first == 0) {
- Emit32(Out, (uint32_t) Data.second.st_ino);
- Emit32(Out, (uint32_t) Data.second.st_dev);
- Emit16(Out, (uint16_t) Data.second.st_mode);
- Emit64(Out, (uint64_t) Data.second.st_mtime);
- Emit64(Out, (uint64_t) Data.second.st_size);
- }
+ Emit32(Out, (uint32_t) Data.st_ino);
+ Emit32(Out, (uint32_t) Data.st_dev);
+ Emit16(Out, (uint16_t) Data.st_mode);
+ Emit64(Out, (uint64_t) Data.st_mtime);
+ Emit64(Out, (uint64_t) Data.st_size);
assert(Out.tell() - Start == DataLen && "Wrong data length");
}