`<regex>`: Remove match mode `_Skip_zero_length` by muellerj2 · Pull Request #6262 · microsoft/STL · GitHub
Skip to content

<regex>: Remove match mode _Skip_zero_length#6262

Merged
StephanTLavavej merged 7 commits into
microsoft:mainfrom
muellerj2:regex-remove-matchmode-skip-zero-length
Apr 29, 2026
Merged

<regex>: Remove match mode _Skip_zero_length#6262
StephanTLavavej merged 7 commits into
microsoft:mainfrom
muellerj2:regex-remove-matchmode-skip-zero-length

Conversation

@muellerj2

@muellerj2 muellerj2 commented Apr 18, 2026

Copy link
Copy Markdown

This removes a strange internal match mode _Skip_zero_length. Its only purpose was to shift the start of the pattern search one position later, but to set prefix().first in the match_results object as if there were no such shift. This match mode was only used to implement the increment operator of regex_iterator.

Moreover, _Regex_search2 has an additional parameter _Org which is only used to set the member _Org in the match_results object.

This PR removes this internal match mode _Skip_zero_length and replaces it in regex_iterator by using another internal match mode, _Match_not_null. This sometimes reduces the number of constructed matcher objects in the zero-length match case, which can improve performance by avoiding some unnecessary allocations. But the fusion of two regex_search calls means that the implementation deviates a bit further from the specification in [re.regiter.incr]: This necessitates some additional logic to emulate the match_prev_avail update to the match flags, because the original spec allows the caller to differentiate in some cases whether the first or the second call to regex_search() succeeded when incrementing from an initial zero-length match. The new tests make sure that this alternate logic behaves like the spec. (We do not have to emulate this logic strictly if the regex search fails, because the value of the match flags member is irrelevant for the end-of-sequence iterator.)

Moreover, this PR moves the update of the match_results field _Org outside _Regex_search2/3. Instead, the callers have to set this member correctly now. This allows the removal of the _Org parameter from _Regex_search2/3. Note that the callers were already responsible for choosing the value of _Org; they just didn't assign it themselves, but instead passed it to _Regex_search which performed the assignment (and did nothing else with this argument).

Drive-by change: _STD-qualify a few more calls.

Drive-by bugfix: I think regex_iterator::operator++() failed to call _Adopt(nullptr) in debug mode in one case when no more match was found.

@muellerj2 muellerj2 requested a review from a team as a code owner April 18, 2026 20:48
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Apr 18, 2026
Comment thread stl/inc/regex Outdated
Comment thread stl/inc/regex Outdated
@StephanTLavavej StephanTLavavej added enhancement Something can be improved regex meow is a substring of homeowner labels Apr 19, 2026
@StephanTLavavej StephanTLavavej added performance Must go faster and removed enhancement Something can be improved labels Apr 20, 2026
@StephanTLavavej StephanTLavavej self-assigned this Apr 20, 2026
Comment thread tests/std/tests/VSO_0000000_regex_use/test.cpp Outdated
Comment thread tests/std/tests/VSO_0000000_regex_use/test.cpp Outdated
Comment thread tests/std/tests/VSO_0000000_regex_use/test.cpp Outdated
Comment thread tests/std/tests/VSO_0000000_regex_use/test.cpp Outdated
@StephanTLavavej StephanTLavavej removed their assignment Apr 22, 2026
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Apr 22, 2026
@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Apr 28, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

@StephanTLavavej StephanTLavavej merged commit fbb8966 into microsoft:main Apr 29, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Apr 29, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster regex meow is a substring of homeowner

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants