From 9034f7c51ef6437ce9d4547ba5bde217b4740fb2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 19 Apr 2022 11:10:53 +0200 Subject: Use target recipe for auxiliary data storage during match-apply In particular, we now have separate auxiliary data storage for inner and outer operations. --- libbuild2/version/rule.cxx | 39 ++++++++++++++++++++++++++++++++------- libbuild2/version/rule.hxx | 3 +++ 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'libbuild2/version') diff --git a/libbuild2/version/rule.cxx b/libbuild2/version/rule.cxx index ad26da4..1799666 100644 --- a/libbuild2/version/rule.cxx +++ b/libbuild2/version/rule.cxx @@ -46,6 +46,25 @@ namespace build2 // in_rule // + + // Wrap the in::rule's perform_update recipe into a data-carrying recipe. + // + // To optimize this a bit further (i.e., to avoid the dynamic memory + // allocation) we are going to call in::rule::perform_update() directly + // (after all it's virtual and thus part of the in_rule's interface). + // + struct match_data + { + const module& mod; + const in_rule& rule; + + target_state + operator() (action a, const target& t) + { + return rule.perform_update (a, t); + } + }; + bool in_rule:: match (action a, target& xt) const { @@ -74,14 +93,20 @@ namespace build2 if (!fi) l5 ([&]{trace << "no in file prerequisite for target " << t;}); - bool r (fm && fi); + return fm && fi; + } + + recipe in_rule:: + apply (action a, target& t) const + { + recipe r (rule::apply (a, t)); - // If we match, lookup and cache the module for the update operation. + // Lookup and cache the module for the update operation. // - if (r && a == perform_update_id) - t.data (rs.find_module (module::name)); - - return r; + return a == perform_update_id + ? match_data {*t.root_scope ().find_module (module::name), + *this} + : move (r); } string in_rule:: @@ -97,7 +122,7 @@ namespace build2 // Note that this code will be executed during up-to-date check for each // substitution so let's try not to do anything overly sub-optimal here. // - const module& m (*t.data ()); + const module& m (t.data (a).mod); // Split it into the package name and the variable/condition name. // diff --git a/libbuild2/version/rule.hxx b/libbuild2/version/rule.hxx index 55b4aee..ba673e5 100644 --- a/libbuild2/version/rule.hxx +++ b/libbuild2/version/rule.hxx @@ -25,6 +25,9 @@ namespace build2 virtual bool match (action, target&) const override; + virtual recipe + apply (action, target&) const override; + virtual string lookup (const location&, action, -- cgit v1.1