From: Nico Weber Date: Tue, 30 Apr 2013 15:44:25 +0000 (-0700) Subject: Move updating DepsLog's deps_ array into its own function. X-Git-Tag: v1.3.0~1^2~7^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=20942b8cf86da96eb4288138fba72c2609cfd54d;p=platform%2Fupstream%2Fninja.git Move updating DepsLog's deps_ array into its own function. No functionality change. --- 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() 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);