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

Some minor regexp matching perf improvements #16405

Merged
merged 2 commits into from Dec 28, 2023
Merged

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Dec 27, 2023

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

This fixes some inefficient regexp matching (creating unused captures) that Performance/RegexpMatch fails to catch.

Copy link
Member

@Bo98 Bo98 left a comment

Choose a reason for hiding this comment

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

Apart from the utils/curl.rb change, LGTM.

I have some nits in regards to safe navigation.

Library/Homebrew/utils/curl.rb Outdated Show resolved Hide resolved
Library/Homebrew/rubocops/extend/formula_cop.rb Outdated Show resolved Hide resolved
Library/Homebrew/cask/audit.rb Outdated Show resolved Hide resolved
Library/Homebrew/dev-cmd/bottle.rb Outdated Show resolved Hide resolved
Library/Homebrew/formula_text_auditor.rb Outdated Show resolved Hide resolved
Library/Homebrew/keg_relocate.rb Outdated Show resolved Hide resolved
Library/Homebrew/livecheck/strategy/git.rb Outdated Show resolved Hide resolved
Library/Homebrew/test/cask/audit_spec.rb Outdated Show resolved Hide resolved
Copy link
Member

@Bo98 Bo98 left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -32,12 +32,12 @@ def to_s
end

def line_number(regex, skip = 0)
index = @lines.drop(skip).index { |line| line =~ regex }
index = @lines.drop(skip).index { |line| line.match?(regex) }
index ? index + 1 : nil
end

def reverse_line_number(regex)
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Can we delete this method? I think the only use was removed in 413a7e5#diff-0718ff8226ebdfd9a6b515e3c2017968bf77c4dad21e7cd6bdbd84c7d6c479c4L292

Copy link
Member

@Bo98 Bo98 Dec 28, 2023

Choose a reason for hiding this comment

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

Looks like the whole class can be removed and its reference replaced with a file read as it seems the only thing called is to_s?

Generally speaking, RuboCop is the successor of this.

@Bo98 Bo98 merged commit 84c2360 into Homebrew:master Dec 28, 2023
24 checks passed
@github-actions github-actions bot added the outdated PR was locked due to age label Jan 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants