Permalink
Browse files

string include method is 10x faster than creating

a new regex object every single time

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 8154f4b commit c5bfc6abe4fd160814f09b02afe68d7f4e25e3d6 Neeraj Singh committed with josevalim Nov 22, 2010
Showing with 1 addition and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -174,7 +174,7 @@ def parse(accept_header)
# input: 'application'
# returend value: [Mime::HTML, Mime::JS, Mime::XML, Mime::YAML, Mime::ATOM, Mime::JSON, Mime::RSS, Mime::URL_ENCODED_FORM
def parse_data_with_trailing_star(input)
- keys = Mime::LOOKUP.keys.select{|k| Regexp.new(input).match(k)}
+ keys = Mime::LOOKUP.keys.select{|k| k.include?(input)}
Mime::LOOKUP.select {|k,_| keys.include?(k)}.collect{|i| i[1]}.inject([]){|all,e| all.include?(e) ? all : all << e}
end
end

0 comments on commit c5bfc6a

Please sign in to comment.