Skip to content

Commit

Permalink
Prefer 'Regexp#match?' over 'Regexp#=~' when the result is not needed (
Browse files Browse the repository at this point in the history
…#98)

'=~' allocates a MatchData, 'match?' does not
  • Loading branch information
jamescook authored Feb 11, 2021
1 parent e26d45e commit 6d5fe27
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/stitches/valid_mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ValidMimeType < Stitches::AllowlistMiddleware

def do_call(env)
accept = String(env["HTTP_ACCEPT"])
if (accept =~ %r{application/json} && accept =~ %r{version=\d+}) || accept =~ %r{application/protobuf}
if (%r{application/json}.match?(accept) && %r{version=\d+}.match?(accept)) || %r{application/protobuf}.match?(accept)
@app.call(env)
else
not_acceptable_response(accept)
Expand Down

0 comments on commit 6d5fe27

Please sign in to comment.