提交 c5bfc6ab 编写于 作者: N Neeraj Singh 提交者: José Valim

string include method is 10x faster than creating

a new regex object every single time
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 8154f4b8
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册