diff options
author | nagachika <nagachika@ruby-lang.org> | 2023-12-16 10:36:58 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2023-12-16 10:48:39 +0900 |
commit | affd2c02962a83b353acd846d99500f3b7994009 (patch) | |
tree | 24c03ae7143057e27bff1777cd9c2eb72433872e | |
parent | ca83700944623d5934a6979ed209733045ac541c (diff) |
merge revision(s) 0300ea5a6c8a7a49feed73318fc8a991aa89fcfc:
[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
---
lib/net/http/header.rb | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
-rw-r--r-- | lib/net/http/header.rb | 12 | ||||
-rw-r--r-- | version.h | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb index b704860c90..ec5552f04d 100644 --- a/lib/net/http/header.rb +++ b/lib/net/http/header.rb @@ -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 @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 2 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 143 +#define RUBY_PATCHLEVEL 144 #include "ruby/version.h" #include "ruby/internal/abi.h" |