diff options
author | Petr Wolf <petr.wolf@gmail.com> | 2012-10-04 19:42:15 (GMT) |
---|---|---|
committer | Petr Wolf <petr.wolf@gmail.com> | 2012-10-04 19:42:15 (GMT) |
commit | 931aac42522c7e4a340cc77bb115ba89d808c7a5 (patch) | |
tree | 0ef58a12f8872fa7e112cb52aa5842fb5cb1d27a | |
parent | 44f2cb66a72f1061b400bcd45a085eb7a0ec8846 (diff) | |
download | Ninja-931aac42522c7e4a340cc77bb115ba89d808c7a5.zip Ninja-931aac42522c7e4a340cc77bb115ba89d808c7a5.tar.gz Ninja-931aac42522c7e4a340cc77bb115ba89d808c7a5.tar.bz2 |
Improve the efficiency of -t clean
Prevent each node from being examined for cleaning multiple times, if it
is used in several other nodes
-rw-r--r-- | src/clean.cc | 12 | ||||
-rw-r--r-- | src/clean.h | 1 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/clean.cc b/src/clean.cc index 3fe23ec..c9d4cbd 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -29,6 +29,7 @@ Cleaner::Cleaner(State* state, const BuildConfig& config) : state_(state), config_(config), removed_(), + cleaned_(), cleaned_files_count_(0), disk_interface_(new RealDiskInterface), status_(0) { @@ -40,6 +41,7 @@ Cleaner::Cleaner(State* state, : state_(state), config_(config), removed_(), + cleaned_(), cleaned_files_count_(0), disk_interface_(disk_interface), status_(0) { @@ -134,9 +136,16 @@ void Cleaner::DoCleanTarget(Node* target) { } for (vector<Node*>::iterator n = e->inputs_.begin(); n != e->inputs_.end(); ++n) { - DoCleanTarget(*n); + Node* next = *n; + // call DoCleanTarget recursively if this node has not been visited + if (cleaned_.count(next) == 0) { + DoCleanTarget(next); + } } } + + // mark this target to be cleaned already + cleaned_.insert(target); } int Cleaner::CleanTarget(Node* target) { @@ -249,4 +258,5 @@ void Cleaner::Reset() { status_ = 0; cleaned_files_count_ = 0; removed_.clear(); + cleaned_.clear(); } diff --git a/src/clean.h b/src/clean.h index 5938dff..8359901 100644 --- a/src/clean.h +++ b/src/clean.h @@ -95,6 +95,7 @@ class Cleaner { State* state_; const BuildConfig& config_; set<string> removed_; + set<Node*> cleaned_; int cleaned_files_count_; DiskInterface* disk_interface_; int status_; |