aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/adhoc-rule-regex-pattern.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-04-20 10:55:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-04-20 10:55:50 +0200
commit9b138ccbebdcdc6bfdd6f6d52e534ae14df280af (patch)
tree04142d3c54864d2f18605b8a544d79e6ec40a9ae /libbuild2/adhoc-rule-regex-pattern.cxx
parent1b8c19b427f7e0ec6a747df60eb9334a620843b7 (diff)
Replace match_extra::buffer with more general data storage facility
Diffstat (limited to 'libbuild2/adhoc-rule-regex-pattern.cxx')
-rw-r--r--libbuild2/adhoc-rule-regex-pattern.cxx15
1 files changed, 11 insertions, 4 deletions
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,