Skip to content

Commit

Permalink
string include method is 10x faster than creating
Browse files Browse the repository at this point in the history
a new regex object every single time

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

0 comments on commit c5bfc6a

Please sign in to comment.