diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-11-22 13:32:37 -0500 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-11-22 23:06:14 +0100 |
commit | 8154f4b816ea1bb2489fba1829ee99cb75fdf696 (patch) | |
tree | 473cbe88af64efa1f3a9ac2a5308330cb2f4e09e /actionpack/lib | |
parent | cdbbf6fd6bef3f286503859c585ada8fe66a3875 (diff) | |
download | rails-8154f4b816ea1bb2489fba1829ee99cb75fdf696.tar.gz rails-8154f4b816ea1bb2489fba1829ee99cb75fdf696.tar.bz2 rails-8154f4b816ea1bb2489fba1829ee99cb75fdf696.zip |
Compile regex only once
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 3b5c1d50f2..f2ccf1784b 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -80,6 +80,9 @@ module Mime end class << self + + TRAILING_STAR_REGEXP = /(\w+)\/\*/ + def lookup(string) LOOKUP[string] end @@ -103,11 +106,10 @@ module Mime ([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last } end - def parse(accept_header) if accept_header !~ /,/ - if result = Regexp.new('(\w+)\/\*').match(accept_header) - parse_data_with_trailing_star(result[1]) + if accept_header =~ TRAILING_STAR_REGEXP + parse_data_with_trailing_star($1) else [Mime::Type.lookup(accept_header)] end |