diff options
author | Nico Weber <nicolasweber@gmx.de> | 2013-04-30 15:44:25 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2013-04-30 15:44:25 (GMT) |
commit | 20942b8cf86da96eb4288138fba72c2609cfd54d (patch) | |
tree | 1a74d5aac1c679d712a7a444167dcebad004b447 | |
parent | 8d03d2cf7e572b65cd242a44081b514338e4fd6b (diff) | |
download | Ninja-20942b8cf86da96eb4288138fba72c2609cfd54d.zip Ninja-20942b8cf86da96eb4288138fba72c2609cfd54d.tar.gz Ninja-20942b8cf86da96eb4288138fba72c2609cfd54d.tar.bz2 |
Move updating DepsLog's deps_ array into its own function.
No functionality change.
-rw-r--r-- | src/deps_log.cc | 18 | ||||
-rw-r--r-- | src/deps_log.h | 3 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc index c2587af..8d90765 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -186,13 +186,8 @@ bool DepsLog::Load(const string& path, State* state, string* err) { deps->nodes[i] = nodes_[deps_data[i]]; } - if (out_id >= (int)deps_.size()) - deps_.resize(out_id + 1); - if (deps_[out_id]) { + if (UpdateDeps(out_id, deps)) ++dead_record_count_; - delete deps_[out_id]; - } - deps_[out_id] = deps; } else { StringPiece path(buf, size); Node* node = state->GetNode(path); @@ -281,6 +276,17 @@ bool DepsLog::Recompact(const string& path, string* err) { return true; } +bool DepsLog::UpdateDeps(int out_id, Deps* deps) { + if (out_id >= (int)deps_.size()) + deps_.resize(out_id + 1); + + bool delete_old = deps_[out_id] != NULL; + if (delete_old) + delete deps_[out_id]; + deps_[out_id] = deps; + return delete_old; +} + bool DepsLog::RecordId(Node* node) { uint16_t size = (uint16_t)node->path().size(); fwrite(&size, 2, 1, file_); diff --git a/src/deps_log.h b/src/deps_log.h index 820997e..7270916 100644 --- a/src/deps_log.h +++ b/src/deps_log.h @@ -90,6 +90,9 @@ struct DepsLog { const vector<Deps*>& deps() const { return deps_; } private: + // Updates the in-memory representation. Takes ownership of |deps|. + // Returns true if a prior deps record was deleted. + bool UpdateDeps(int out_id, Deps* deps); // Write a node name record, assigning it an id. bool RecordId(Node* node); |