зеркало из https://github.com/github/ruby.git
[ruby/net-http] Improve performance of HTTPHeader#content_type
In the existing implementation, `main_type` and `sub_type` would end up being called multiple times potentially. Instead of doing that, save the result so it can be re-used. https://github.com/ruby/net-http/commit/179976f7ea
This commit is contained in:
Родитель
8d985b1855
Коммит
0300ea5a6c
|
@ -699,10 +699,14 @@ module Net::HTTPHeader
|
|||
# res.content_type # => "application/json"
|
||||
#
|
||||
def content_type
|
||||
return nil unless main_type()
|
||||
if sub_type()
|
||||
then "#{main_type()}/#{sub_type()}"
|
||||
else main_type()
|
||||
main = main_type()
|
||||
return nil unless main
|
||||
|
||||
sub = sub_type()
|
||||
if sub
|
||||
"#{main}/#{sub}"
|
||||
else
|
||||
main
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче