From 6486c7ac94268728c4255b420d36cb859cd3ea20 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 21 Sep 2015 15:30:02 -0700 Subject: drop array allocations on Mime::Type#=~ Synonyms are always a list of strings, and we have access to the internal string representation, so we can avoid allocating new arrays. --- actionpack/lib/action_dispatch/http/mime_type.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 6a5b1a91e1..a4dfe72c63 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -318,9 +318,7 @@ to: def =~(mime_type) return false unless mime_type regexp = Regexp.new(Regexp.quote(mime_type.to_s)) - (@synonyms + [ self ]).any? do |synonym| - synonym.to_s =~ regexp - end + @synonyms.any? { |synonym| synonym.to_s =~ regexp } || @string =~ regexp end def html? -- cgit v1.2.3