Skip to content

Experiment with inverting Regex scan loop #62443

Closed

Description

@stephentoub

The Regex scan loop is currently along the lines of:

while (true)
{
    if (!FindFirstChar()) return false;
    Go();
    if (matched) return true;
}

This is good for cases where matches don't start at the beginning of the string. However, for cases where the match would likely be at the beginning of the input, a form like:

do
{
    Go();
    if (matched) return true;
}
while (FindFirstChar());
return false;

would likely be better, avoiding the extra FindFirstChar call to validate something which Go is already going to validate.

We should evaluate how much this helps one set of cases vs how much this penalizes the other set of cases, and decide whether it's worth switching. (If we do this, note that certain cases in Go currently assume that FindFirstChar has already performed the match, e.g. if the entire expression is a case-sensitive string... that would need to be removed.)

Activity

  1. added this to the 7.0.0 milestone on Dec 6, 2021
  2. ghost added
    untriaged
    on Dec 6, 2021
  3. removed
    untriaged
    on Dec 15, 2021
  4. ghost locked as resolved and limited conversation to collaborators on Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions