aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/version/rule.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-04-19 11:10:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-04-19 11:10:53 +0200
commit9034f7c51ef6437ce9d4547ba5bde217b4740fb2 (patch)
treebfaa297fda78b6cafe4487e2281420a4cf77c81a /libbuild2/version/rule.cxx
parent457f65414031f45174f3c35230a0c0e1de88b51a (diff)
Use target recipe for auxiliary data storage during match-apply
In particular, we now have separate auxiliary data storage for inner and outer operations.
Diffstat (limited to 'libbuild2/version/rule.cxx')
-rw-r--r--libbuild2/version/rule.cxx39
1 files changed, 32 insertions, 7 deletions
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> (module::name));
-
- return r;
+ return a == perform_update_id
+ ? match_data {*t.root_scope ().find_module<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*> ());
+ const module& m (t.data<match_data> (a).mod);
// Split it into the package name and the variable/condition name.
//