summaryrefslogtreecommitdiffstats
path: root/src/deps_log.cc
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2013-01-07 18:59:27 (GMT)
committerEvan Martin <martine@danga.com>2013-04-08 22:01:36 (GMT)
commitab218230c4c6c3f0bb2a26215d1ac09e397e6065 (patch)
tree46bbac03e80bd3fedf223554d8585955af8f36c7 /src/deps_log.cc
parent58c7139b9f404e18097d4f3ef6adcd49a01e3d73 (diff)
downloadNinja-ab218230c4c6c3f0bb2a26215d1ac09e397e6065.zip
Ninja-ab218230c4c6c3f0bb2a26215d1ac09e397e6065.tar.gz
Ninja-ab218230c4c6c3f0bb2a26215d1ac09e397e6065.tar.bz2
don't write out deps entries if nothing changed
Shortcuts a common case.
Diffstat (limited to 'src/deps_log.cc')
-rw-r--r--src/deps_log.cc32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc
index da6cd93..0f10b5c 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -50,15 +50,43 @@ bool DepsLog::OpenForWrite(const string& path, string* err) {
bool DepsLog::RecordDeps(Node* node, TimeStamp mtime,
const vector<Node*>& nodes) {
+ // Track whether there's any new data to be recorded.
+ bool made_change = false;
+
// Assign ids to all nodes that are missing one.
- if (node->id() < 0)
+ if (node->id() < 0) {
RecordId(node);
+ made_change = true;
+ }
for (vector<Node*>::const_iterator i = nodes.begin();
i != nodes.end(); ++i) {
- if ((*i)->id() < 0)
+ if ((*i)->id() < 0) {
RecordId(*i);
+ made_change = true;
+ }
+ }
+
+ // See if the new data is different than the existing data, if any.
+ if (!made_change) {
+ Deps* deps = GetDeps(node);
+ if (!deps ||
+ deps->mtime != mtime ||
+ deps->node_count != (int)nodes.size()) {
+ made_change = true;
+ } else {
+ for (int i = 0; i < (int)nodes.size(); ++i) {
+ if (deps->nodes[i] != nodes[i]) {
+ made_change = true;
+ break;
+ }
+ }
+ }
}
+ // Don't write anything if there's no new info.
+ if (!made_change)
+ return true;
+
uint16_t size = 4 * (1 + 1 + (uint16_t)nodes.size());
size |= 0x8000; // Deps record: set high bit.
fwrite(&size, 2, 1, file_);