Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce header regexps #2135

Merged
merged 2 commits into from
Oct 23, 2023
Merged

Reduce header regexps #2135

merged 2 commits into from
Oct 23, 2023

Conversation

DrJosh9000
Copy link
Contributor

headerRegex (now headerRE) was used to find headers. Because it was anchored on both ends (^...$), it (morally) had to run through the whole string in order to match, though I hope that the RE2-like regexp engine optimises (.+)?$ to nothing.

We can say the same for headerExpansionRE. Matching \s+ in between ^^^ and +++ just seems unnecessary - we document it as "^^^ +++". So I changed it to \s.

In both cases the new regexps only need to process either 4 or 7 bytes in order to match.

The argument for removing matches of ansiColourRE applies to header expansions as well, so the fact that isHeaderExpansion didn't do the same thing is arguably a bug. Instead, I rearranged things so headerExpansionRE can test the same decolourised line (inside Scan), removing both isHeader and isHeaderExpansion.

@DrJosh9000 DrJosh9000 requested a review from a team June 1, 2023 07:43
@DrJosh9000 DrJosh9000 force-pushed the header-regexps-wat branch from 910a668 to 4f10c77 Compare June 1, 2023 07:44
Copy link
Contributor

@triarius triarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I approve 🎉 Going to just leave a comment to check something. I'll formerly approve it later. It still needs a rebase before merging, though.

headerRegex (now headerRE) was used to find headers. Because it was anchored on both ends (^...$), it (morally) had to run through the whole string in order to match, though I hope that the RE2-like regexp engine optimises (.+)?$ to nothing.

We can say the same for headerExpansionRE. Matching `\s+` in between ^^^ and +++ just seems unnecessary - we document it as "^^^ +++". So I changed it to `\s`.

In both cases the new regexps only need to process either 4 or 7 bytes in order to match.

The argument for removing matches of ansiColourRE applies to header expansions as well, so the fact that isHeaderExpansion didn't do the same thing is arguably a bug. Instead, I rearranged things so headerExpansionRE can test the same decolourised line (inside Scan), removing both isHeader and isHeaderExpansion.
@triarius triarius self-requested a review October 23, 2023 00:30
Copy link
Contributor

@triarius triarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@DrJosh9000 DrJosh9000 enabled auto-merge October 23, 2023 00:32
@DrJosh9000 DrJosh9000 merged commit 224b3d5 into main Oct 23, 2023
@DrJosh9000 DrJosh9000 deleted the header-regexps-wat branch October 23, 2023 00:37
@triarius
Copy link
Contributor

The thing I was checking is whether this PR would appear here https://github.com/pulls/review-requested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants