diff --git a/stl/inc/regex b/stl/inc/regex index adb38897585..d6c17c6dde2 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -3407,21 +3407,6 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Better_match() { // check for bet unsigned int _Res_valid_count = 0; unsigned int _Tgt_state_valid_count = 0; - for (unsigned int _Ix = 0; _Ix < _Get_ncap(); ++_Ix) { - if (_Res._Grp_valid[_Ix]) { - ++_Res_valid_count; - } - - if (_Tgt_state._Grp_valid[_Ix]) { - ++_Tgt_state_valid_count; - } - } - - // more captured groups means a better match - if (_Tgt_state_valid_count != _Res_valid_count) { - return _Tgt_state_valid_count > _Res_valid_count; - } - for (unsigned int _Ix = 0; _Ix < _Get_ncap(); ++_Ix) { // check each capture group if (_Res._Grp_valid[_Ix] && _Tgt_state._Grp_valid[_Ix]) { if (_Res._Grps[_Ix]._Begin != _Tgt_state._Grps[_Ix]._Begin) { @@ -3433,8 +3418,18 @@ bool _Matcher<_BidIt, _Elem, _RxTraits, _It>::_Better_match() { // check for bet return _STD distance(_Begin, _Res._Grps[_Ix]._End) < _STD distance(_Begin, _Tgt_state._Grps[_Ix]._End); } } + + if (_Res._Grp_valid[_Ix]) { + ++_Res_valid_count; + } + + if (_Tgt_state._Grp_valid[_Ix]) { + ++_Tgt_state_valid_count; + } } - return false; + + // more captured groups means a better match + return _Tgt_state_valid_count > _Res_valid_count; } template