Skip to content

Commit b481d3f

Browse files
committed
<regex>: Remove capture extent vectors from stack frames
1 parent ab6dec6 commit b481d3f

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ add_benchmark(path_lexically_normal src/path_lexically_normal.cpp)
125125
add_benchmark(priority_queue_push_range src/priority_queue_push_range.cpp)
126126
add_benchmark(random_integer_generation src/random_integer_generation.cpp)
127127
add_benchmark(ranges_div_ceil src/ranges_div_ceil.cpp)
128+
add_benchmark(regex_match src/regex_match.cpp)
128129
add_benchmark(regex_search src/regex_search.cpp)
129130
add_benchmark(remove src/remove.cpp)
130131
add_benchmark(replace src/replace.cpp)

stl/inc/regex

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,8 @@ enum class _Rx_unwind_ops {
16811681
_Loop_nongreedy,
16821682
_Loop_greedy,
16831683
_Loop_restore_vals,
1684+
_Capture_restore_begin,
1685+
_Capture_restore_end
16841686
};
16851687

16861688
template <class _BidIt>
@@ -1689,7 +1691,7 @@ public:
16891691
_Rx_unwind_ops _Code;
16901692
int _Loop_idx_sav;
16911693
_Node_base* _Node;
1692-
_Tgt_state_t<_BidIt> _Match_state;
1694+
_Bt_state_t<_BidIt> _Match_state;
16931695
size_t _Loop_frame_idx_sav;
16941696
};
16951697

@@ -3946,7 +3948,10 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
39463948
{ // record current position
39473949
_Node_capture* _Node = static_cast<_Node_capture*>(_Nx);
39483950
if (_Node->_Idx != 0U) {
3949-
_Tgt_state._Grps[_Node->_Idx]._Begin = _Tgt_state._Cur;
3951+
auto& _Group = _Tgt_state._Grps[_Node->_Idx];
3952+
auto _Frame_idx = _Push_frame(_Rx_unwind_ops::_Capture_restore_begin, _Node);
3953+
_Frames[_Frame_idx]._Match_state._Cur = _Group._Begin;
3954+
_Group._Begin = _Tgt_state._Cur;
39503955
}
39513956
break;
39523957
}
@@ -3956,8 +3961,11 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
39563961
_Node_end_group* _Node = static_cast<_Node_end_group*>(_Nx);
39573962
_Node_capture* _Node0 = static_cast<_Node_capture*>(_Node->_Back);
39583963
if (_Node0->_Idx != 0U) { // update capture data
3959-
_Tgt_state._Grp_valid[_Node0->_Idx] = true;
3960-
_Tgt_state._Grps[_Node0->_Idx]._End = _Tgt_state._Cur;
3964+
auto& _Group = _Tgt_state._Grps[_Node0->_Idx];
3965+
auto _Frame_idx = _Push_frame(_Rx_unwind_ops::_Capture_restore_end, _Node0);
3966+
_Frames[_Frame_idx]._Match_state._Cur = _Group._End;
3967+
_Tgt_state._Grp_valid[_Node0->_Idx] = true;
3968+
_Group._End = _Tgt_state._Cur;
39613969
}
39623970
break;
39633971
}
@@ -4325,6 +4333,20 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
43254333
}
43264334
break;
43274335

4336+
case _Rx_unwind_ops::_Capture_restore_begin:
4337+
{ // restore begin of capturing group
4338+
auto _Node = static_cast<_Node_capture*>(_Frame._Node);
4339+
_Tgt_state._Grps[_Node->_Idx]._Begin = _Frame._Match_state._Cur;
4340+
}
4341+
break;
4342+
4343+
case _Rx_unwind_ops::_Capture_restore_end:
4344+
{ // restore end of capturing group
4345+
auto _Node = static_cast<_Node_capture*>(_Frame._Node);
4346+
_Tgt_state._Grps[_Node->_Idx]._End = _Frame._Match_state._Cur;
4347+
}
4348+
break;
4349+
43284350
default:
43294351
#if _ITERATOR_DEBUG_LEVEL != 0
43304352
_STL_REPORT_ERROR("internal stack of regex matcher corrupted");

0 commit comments

Comments
 (0)