From 2908afbd6a9222b718c0f910edfbe2fc5943aad8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 28 Nov 2021 10:21:09 +0200 Subject: Avoid unnecessary work in depdb::close() if using static check_mtime() --- libbuild2/adhoc-rule-buildscript.cxx | 2 +- libbuild2/cc/compile-rule.cxx | 2 +- libbuild2/depdb.cxx | 4 ++-- libbuild2/depdb.hxx | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/adhoc-rule-buildscript.cxx b/libbuild2/adhoc-rule-buildscript.cxx index e8bc20d..b981b8d 100644 --- a/libbuild2/adhoc-rule-buildscript.cxx +++ b/libbuild2/adhoc-rule-buildscript.cxx @@ -505,7 +505,7 @@ namespace build2 if (update && dd.reading () && !ctx.dry_run) dd.touch = timestamp_unknown; - dd.close (); + dd.close (false /* mtime_check */); md->dd = move (dd.path); // Pass on base scope and update/mtime. diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index 3c77ad3..db9e6cb 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -1424,7 +1424,7 @@ namespace build2 if (u && dd.reading () && !ctx.dry_run) dd.touch = timestamp_unknown; - dd.close (); + dd.close (false /* mtime_check */); md.dd = move (dd.path); // If the preprocessed output is suitable for compilation, then pass diff --git a/libbuild2/depdb.cxx b/libbuild2/depdb.cxx index 1215e78..e50870c 100644 --- a/libbuild2/depdb.cxx +++ b/libbuild2/depdb.cxx @@ -281,7 +281,7 @@ namespace build2 } void depdb:: - close () + close (bool mc) { // If we are at eof, then it means all lines are good, there is the "end // marker" at the end, and we don't need to do anything, except, maybe @@ -329,7 +329,7 @@ namespace build2 change (true /* truncate */); } - if (mtime_check ()) + if (mc && mtime_check ()) start_ = system_clock::now (); if (state_ == state::write) diff --git a/libbuild2/depdb.hxx b/libbuild2/depdb.hxx index 9cff281..5b5052d 100644 --- a/libbuild2/depdb.hxx +++ b/libbuild2/depdb.hxx @@ -118,10 +118,12 @@ namespace build2 // function will "chop off" lines that haven't been read. // // Make sure to also call check_mtime() after updating the target to - // perform the target/database modification times sanity checks. + // perform the target/database modification times sanity checks. Pass + // false to close() to avoid unnecessary work if using the static version + // of check_mtime() (or not using it at all for some reason). // void - close (); + close (bool mtime_check = true); // Flush any unwritten data to disk. This is primarily useful when reusing // a (partially written) database as an input to external programs (e.g., -- cgit v1.1