diff options
-rw-r--r-- | src/disk_interface.cc | 21 | ||||
-rw-r--r-- | src/disk_interface.h | 5 |
2 files changed, 8 insertions, 18 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc index fa0aa3d..290975b 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -168,15 +168,14 @@ TimeStamp RealDiskInterface::Stat(const string& path) { Cache::iterator ci = cache_.find(dir); if (ci == cache_.end()) { - DirCache* dc = new DirCache; - if (!StatAllFilesInDir(dir.empty() ? "." : dir, dc, quiet_)) { - delete dc; + ci = cache_.insert(make_pair(dir, DirCache())).first; + if (!StatAllFilesInDir(dir.empty() ? "." : dir, &ci->second, quiet_)) { + cache_.erase(ci); return -1; } - ci = cache_.insert(make_pair(dir, dc)).first; } - DirCache::iterator di = ci->second->find(base); - return di != ci->second->end() ? di->second : 0; + DirCache::iterator di = ci->second.find(base); + return di != ci->second.end() ? di->second : 0; #else struct stat st; if (stat(path.c_str(), &st) < 0) { @@ -254,14 +253,6 @@ void RealDiskInterface::AllowStatCache(bool allow) { #ifdef _WIN32 use_cache_ = allow; if (!use_cache_) - ClearCache(); -#endif -} - -void RealDiskInterface::ClearCache() { -#ifdef _WIN32 - for (Cache::iterator it = cache_.begin(), end = cache_.end(); it != end; ++it) - delete it->second; - cache_.clear(); + cache_.clear(); #endif } diff --git a/src/disk_interface.h b/src/disk_interface.h index 0f6dfd3..b152a62 100644 --- a/src/disk_interface.h +++ b/src/disk_interface.h @@ -61,7 +61,7 @@ struct RealDiskInterface : public DiskInterface { , use_cache_(false) #endif {} - virtual ~RealDiskInterface() { ClearCache(); } + virtual ~RealDiskInterface() {} virtual TimeStamp Stat(const string& path); virtual bool MakeDir(const string& path); virtual bool WriteFile(const string& path, const string& contents); @@ -82,10 +82,9 @@ struct RealDiskInterface : public DiskInterface { typedef map<string, TimeStamp> DirCache; // TODO: Neither a map nor a hashmap seems ideal here. If the statcache // works out, come up with a better data structure. - typedef map<string, DirCache*> Cache; + typedef map<string, DirCache> Cache; Cache cache_; #endif - void ClearCache(); }; #endif // NINJA_DISK_INTERFACE_H_ |