Move updating DepsLog's deps_ array into its own function.
authorNico Weber <nicolasweber@gmx.de>
Tue, 30 Apr 2013 15:44:25 +0000 (08:44 -0700)
committerNico Weber <nicolasweber@gmx.de>
Tue, 30 Apr 2013 15:44:25 +0000 (08:44 -0700)
No functionality change.

src/deps_log.cc
src/deps_log.h

index c2587af..8d90765 100644 (file)
@@ -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_);
index 820997e..7270916 100644 (file)
@@ -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);