Permalink
Browse files

Compile regex only once

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent cdbbf6f commit 8154f4b816ea1bb2489fba1829ee99cb75fdf696 Neeraj Singh committed with josevalim Nov 22, 2010
Showing with 5 additions and 3 deletions.
  1. +5 −3 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -80,6 +80,9 @@ def ==(item)
end
class << self
+
+ TRAILING_STAR_REGEXP = /(\w+)\/\*/
+
def lookup(string)
LOOKUP[string]
end
@@ -103,11 +106,10 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
([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

0 comments on commit 8154f4b

Please sign in to comment.