[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:
Josh Nichols 2023-08-13 12:55:29 -04:00 коммит произвёл git
Родитель 8d985b1855
Коммит 0300ea5a6c
1 изменённых файлов: 8 добавлений и 4 удалений

Просмотреть файл

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