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
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?This fixes some inefficient regexp matching (creating unused captures) that Performance/RegexpMatch fails to catch.