If __rep_count.second is already 1 we don't need to add a cleanup frame
to restore it to 1.
This reduces the maximum size of the __frames stack by 12% for
regex_match(string(200000, 'a'), "(a|b|c)*").
PR libstdc++/86164
libstdc++-v3/ChangeLog:
* include/bits/regex_executor.tcc: Only add a
restore_rep_count_val frame when necessary.
---
libstdc++-v3/include/bits/regex_executor.tcc | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libstdc++-v3/include/bits/regex_executor.tcc
b/libstdc++-v3/include/bits/regex_executor.tcc
index 0e78cb2e2c87..ca631fb77ce9 100644
--- a/libstdc++-v3/include/bits/regex_executor.tcc
+++ b/libstdc++-v3/include/bits/regex_executor.tcc
@@ -181,12 +181,15 @@ namespace __detail
auto& __rep_count = _M_rep_count[__i];
if (__rep_count.second == 0 || __rep_count.first != _M_current)
{
- __frames.emplace_back(_S_fopcode_restore_rep_count_val,
- __i, __rep_count.second);
+ if (__rep_count.second != 1)
+ {
+ __frames.emplace_back(_S_fopcode_restore_rep_count_val,
+ __i, __rep_count.second);
+ __rep_count.second = 1;
+ }
__frames.emplace_back(_S_fopcode_restore_rep_count_pos,
__i, __rep_count.first);
__rep_count.first = _M_current;
- __rep_count.second = 1;
__frames.emplace_back(_S_fopcode_next, __state._M_alt);
}
else
--
2.53.0.rc0.25.gb5c409c40f