From 9b138ccbebdcdc6bfdd6f6d52e534ae14df280af Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 20 Apr 2022 10:55:50 +0200 Subject: Replace match_extra::buffer with more general data storage facility --- libbuild2/adhoc-rule-regex-pattern.cxx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'libbuild2/adhoc-rule-regex-pattern.cxx') diff --git a/libbuild2/adhoc-rule-regex-pattern.cxx b/libbuild2/adhoc-rule-regex-pattern.cxx index 98acfb6..59a63bc 100644 --- a/libbuild2/adhoc-rule-regex-pattern.cxx +++ b/libbuild2/adhoc-rule-regex-pattern.cxx @@ -197,11 +197,18 @@ namespace build2 // iterators pointing to the string being matched. Which means this string // must be kept around until we are done with replacing the subsitutions. // In fact, we cannot even move it because this may invalidate the - // iterators (e.g., in case of a small string optimization). So the plan - // is to store the string in match_extra::buffer and regex_match_results - // (which we can move) in the auxiliary data storage. + // iterators (e.g., in case of a small string optimization). We also + // cannot set the data ahead of time because we may not match. Plus, + // resorting to a dynamic memory allocation even if we don't match feels + // heavy-handed. // - string& ns (me.buffer); + // So the plan is to store the string in match_extra::data() and + // regex_match_results (which we can move) in the auxiliary data storage. + // + static_assert (sizeof (string) <= match_extra::data_size, + "match data too large"); + + string& ns (me.data (string ())); auto append_name = [&ns, first = true, -- cgit v1.1