mirror of https://github.com/rails/rails
Fix Performance/StringInclude that RuboCop can't
This replaces two instances of /html/.match?(<string>) with the more
performant <string>.include?("html").
Performance/StringInclude was enabled in 3158bbb
, however RuboCop does
not flag these two because it is unable to determine that the variable
passed to #match? is a string. In both these cases we know that the
variable must be a string (Mime::Type must be initialized with a string,
and Content-Type must be a string if present per Rack SPEC)
These were found by `rg '/\[\w ]+/\.match\?'`, and while this search
returns other entries they are either comments or in test files.
This commit is contained in:
parent
ae569eaef8
commit
583ce94c22
|
@ -293,7 +293,7 @@ module Mime
|
|||
end
|
||||
|
||||
def html?
|
||||
(symbol == :html) || /html/.match?(@string)
|
||||
(symbol == :html) || @string.include?("html")
|
||||
end
|
||||
|
||||
def all?; false; end
|
||||
|
|
|
@ -55,7 +55,7 @@ module ActionDispatch # :nodoc:
|
|||
private
|
||||
def html_response?(headers)
|
||||
if content_type = headers[CONTENT_TYPE]
|
||||
/html/.match?(content_type)
|
||||
content_type.include?("html")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue