ruby-changes:73866
From: Jean <ko1@a...>
Date: Thu, 6 Oct 2022 16:56:08 +0900 (JST)
Subject: [ruby-changes:73866] d15b38d944 (master): [ruby/open-uri] Avoid busting the global constant cache
https://git.ruby-lang.org/ruby.git/commit/?id=d15b38d944 From d15b38d944c27cb627741206d8adf285153a4df2 Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Fri, 18 Feb 2022 09:45:13 +0100 Subject: [ruby/open-uri] Avoid busting the global constant cache `Object#extend(mod)` bump the global constant cache if the module has constants of its own. So by moving these constants outside of `Meta` we avoid bumping the cache. https://github.com/ruby/open-uri/commit/363c399bac --- lib/open-uri.rb | 14 +++++++------- test/open-uri/test_open-uri.rb | 10 +++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/open-uri.rb b/lib/open-uri.rb index cb9c3aa505..36bc3e7266 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -410,6 +410,13 @@ module OpenURI https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb#L410 end end + # :stopdoc: + RE_LWS = /[\r\n\t ]+/n + RE_TOKEN = %r{[^\x00- ()<>@,;:\\"/\[\]?={}\x7f]+}n + RE_QUOTED_STRING = %r{"(?:[\r\n\t !#-\[\]-~\x80-\xff]|\\[\x00-\x7f])*"}n + RE_PARAMETERS = %r{(?:;#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?=#{RE_LWS}?(?:#{RE_TOKEN}|#{RE_QUOTED_STRING})#{RE_LWS}?)*}n + # :startdoc: + # Mixin for holding meta-information. module Meta def Meta.init(obj, src=nil) # :nodoc: @@ -487,13 +494,6 @@ module OpenURI https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb#L494 end end - # :stopdoc: - RE_LWS = /[\r\n\t ]+/n - RE_TOKEN = %r{[^\x00- ()<>@,;:\\"/\[\]?={}\x7f]+}n - RE_QUOTED_STRING = %r{"(?:[\r\n\t !#-\[\]-~\x80-\xff]|\\[\x00-\x7f])*"}n - RE_PARAMETERS = %r{(?:;#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?=#{RE_LWS}?(?:#{RE_TOKEN}|#{RE_QUOTED_STRING})#{RE_LWS}?)*}n - # :startdoc: - def content_type_parse # :nodoc: vs = @metas['content-type'] # The last (?:;#{RE_LWS}?)? matches extra ";" which violates RFC2045. diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index 72ebcdb0da..afdd63ae85 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -902,5 +902,13 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L902 } end -end + def test_meta_init_doesnt_bump_global_constant_state + skip "RubyVM.stat not defined" unless defined? RubyVM.stat + + OpenURI::Meta.init(Object.new) # prewarm + before = RubyVM.stat(:global_constant_state) + OpenURI::Meta.init(Object.new) + assert_equal 0, RubyVM.stat(:global_constant_state) - before + end +end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/