Skip to content

Commit 0300ea5

Browse files
technicalpicklesmatzbot
authored andcommitted
[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. ruby/net-http@179976f7ea
1 parent 8d985b1 commit 0300ea5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/net/http/header.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,14 @@ def range_length
699699
# res.content_type # => "application/json"
700700
#
701701
def content_type
702-
return nil unless main_type()
703-
if sub_type()
704-
then "#{main_type()}/#{sub_type()}"
705-
else main_type()
702+
main = main_type()
703+
return nil unless main
704+
705+
sub = sub_type()
706+
if sub
707+
"#{main}/#{sub}"
708+
else
709+
main
706710
end
707711
end
708712

0 commit comments

Comments
 (0)