summaryrefslogtreecommitdiffstats
path: root/src/state.cc
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-12-07 16:55:46 (GMT)
committerEvan Martin <martine@danga.com>2011-12-07 16:55:46 (GMT)
commit5394fefc2bc297e3c7bc13d8c54823f34d82877c (patch)
tree3fe298bd44b2d4562d1245b1d8007dbe69cb751c /src/state.cc
parentc6144ccfe366b694bf034bdafa07e7c47ac8bf30 (diff)
downloadNinja-5394fefc2bc297e3c7bc13d8c54823f34d82877c.zip
Ninja-5394fefc2bc297e3c7bc13d8c54823f34d82877c.tar.gz
Ninja-5394fefc2bc297e3c7bc13d8c54823f34d82877c.tar.bz2
merge StatCache into State
I think I had originally imagined StatCache would contain more state, but at this point it's clear it was just managing a single map, which could just as well be in the already-small State object.
Diffstat (limited to 'src/state.cc')
-rw-r--r--src/state.cc42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/state.cc b/src/state.cc
index bbb2f6a..1635f31 100644
--- a/src/state.cc
+++ b/src/state.cc
@@ -15,7 +15,9 @@
#include "state.h"
#include <assert.h>
+#include <stdio.h>
+#include "edit_distance.h"
#include "graph.h"
#include "util.h"
@@ -46,15 +48,36 @@ Edge* State::AddEdge(const Rule* rule) {
}
Node* State::GetNode(const string& path) {
- return stat_cache_.GetFile(path);
+ Node* node = LookupNode(path);
+ if (node)
+ return node;
+ node = new Node(path);
+ paths_[node->path().c_str()] = node;
+ return node;
}
Node* State::LookupNode(const string& path) {
- return stat_cache_.LookupFile(path);
+ Paths::iterator i = paths_.find(path.c_str());
+ if (i != paths_.end())
+ return i->second;
+ return NULL;
}
Node* State::SpellcheckNode(const string& path) {
- return stat_cache_.SpellcheckFile(path);
+ const bool kAllowReplacements = true;
+ const int kMaxValidEditDistance = 3;
+
+ int min_distance = kMaxValidEditDistance + 1;
+ Node* result = NULL;
+ for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) {
+ int distance = EditDistance(
+ i->first, path, kAllowReplacements, kMaxValidEditDistance);
+ if (distance < min_distance && i->second) {
+ min_distance = distance;
+ result = i->second;
+ }
+ }
+ return result;
}
void State::AddIn(Edge* edge, const string& path) {
@@ -106,7 +129,18 @@ vector<Node*> State::DefaultNodes(string* err) {
}
void State::Reset() {
- stat_cache_.Invalidate();
+ for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i)
+ i->second->ResetState();
for (vector<Edge*>::iterator e = edges_.begin(); e != edges_.end(); ++e)
(*e)->outputs_ready_ = false;
}
+
+void State::Dump() {
+ for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) {
+ Node* node = i->second;
+ printf("%s %s\n",
+ node->path().c_str(),
+ node->status_known() ? (node->dirty() ? "dirty" : "clean")
+ : "unknown");
+ }
+}