summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2014-06-15 21:11:27 (GMT)
committerNico Weber <thakis@chromium.org>2014-06-15 21:13:54 (GMT)
commit726afc8226a10cd6c5ce724a845ff5cd17169091 (patch)
tree2c19ad79d9356ea6e63ba710fa8d92d532f0c491 /src
parent9970174e2ab8e4d5c9f333b795c8d284cf1cb8f5 (diff)
downloadNinja-726afc8226a10cd6c5ce724a845ff5cd17169091.zip
Ninja-726afc8226a10cd6c5ce724a845ff5cd17169091.tar.gz
Ninja-726afc8226a10cd6c5ce724a845ff5cd17169091.tar.bz2
Free cache memory once it's no longer used.
Doesn't slow down empty build times measurably, and saves some memory on non-empty builds.
Diffstat (limited to 'src')
-rw-r--r--src/disk_interface.cc16
-rw-r--r--src/disk_interface.h6
-rw-r--r--src/ninja.cc9
3 files changed, 23 insertions, 8 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index cd99915..ff86ed1 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -230,3 +230,19 @@ int RealDiskInterface::RemoveFile(const string& path) {
return 0;
}
}
+
+void RealDiskInterface::AllowCache(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();
+#endif
+}
diff --git a/src/disk_interface.h b/src/disk_interface.h
index bb40dc9..40c24b6 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() {}
+ virtual ~RealDiskInterface() { ClearCache(); }
virtual TimeStamp Stat(const string& path);
virtual bool MakeDir(const string& path);
virtual bool WriteFile(const string& path, const string& contents);
@@ -70,6 +70,9 @@ struct RealDiskInterface : public DiskInterface {
/// Whether to print on errors. Used to make a test quieter.
bool quiet_;
+
+ /// Whether stat information can be cached.
+ void AllowCache(bool allow);
#ifdef _WIN32
/// Whether stat information can be cached.
bool use_cache_;
@@ -80,6 +83,7 @@ struct RealDiskInterface : public DiskInterface {
typedef map<string, DirCache*> Cache;
Cache cache_;
#endif
+ void ClearCache();
};
#endif // NINJA_DISK_INTERFACE_H_
diff --git a/src/ninja.cc b/src/ninja.cc
index cace2a0..eedfec0 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -889,10 +889,7 @@ int NinjaMain::RunBuild(int argc, char** argv) {
return 1;
}
-#ifdef _WIN32
- if (g_experimental_win_statcache)
- disk_interface_.use_cache_ = true;
-#endif
+ disk_interface_.AllowCache(g_experimental_win_statcache);
Builder builder(&state_, config_, &build_log_, &deps_log_, &disk_interface_);
for (size_t i = 0; i < targets.size(); ++i) {
@@ -907,10 +904,8 @@ int NinjaMain::RunBuild(int argc, char** argv) {
}
}
-#ifdef _WIN32
// Make sure restat rules do not see stale timestamps.
- disk_interface_.use_cache_ = false;
-#endif
+ disk_interface_.AllowCache(false);
if (builder.AlreadyUpToDate()) {
printf("ninja: no work to do.\n");