<regex>: Simplify matching of _N_if NFA nodes in leftmost-longest mode by muellerj2 · Pull Request #5405 · microsoft/STL (original) (raw)

Since we settled on some reasonable semantics for leftmost-longest matching in #5218, I think we should remove the code for some other (abandoned) attempt to implement the leftmost-longest rule in _Matcher::_Do_if: An attempt to set Tgt_state to the leftmost-longest match found under this _N_if node.

This is neither necessary (in leftmost-longest mode, we take the final result from _Res, not _Tgt_state) nor sufficient (it assigns one of the longest matches to _Tgt_state, but if there are several of the same length it doesn't necessarily pick the correct one among these matches).

On the other hand, this saves 96 bytes of stack space per call to _Do_if in debug mode, slightly alleviating the stack overflow issues (#997, #1528).

Potentially leaving _Tgt_state in a garbage state is fine here, because none of the functions further up on the callstack rely on its value:

So in all cases, either Tgt_state isn't evaluated anymore or it is reset to some savepoint before it is used again.