Compile regex only once

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Neeraj Singh
2010-11-22 13:32:37 -05:00
committed by José Valim
parent cdbbf6fd6b
commit 8154f4b816

View File

@@ -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