summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2014-06-16 17:27:10 (GMT)
committerNico Weber <thakis@chromium.org>2014-06-16 17:27:10 (GMT)
commit9bdb0644d141a1e376e4fd0aee1b373a3a7c3468 (patch)
treeecae9d7970efa89463562b3dc730ef6fbf4180ba /src
parentf0b83f7812114cfe9f5f1d32fe8fb53dff8cecba (diff)
downloadNinja-9bdb0644d141a1e376e4fd0aee1b373a3a7c3468.zip
Ninja-9bdb0644d141a1e376e4fd0aee1b373a3a7c3468.tar.gz
Ninja-9bdb0644d141a1e376e4fd0aee1b373a3a7c3468.tar.bz2
simplify statcache code more
Diffstat (limited to 'src')
-rw-r--r--src/disk_interface.cc21
-rw-r--r--src/disk_interface.h5
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_