diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2022-02-18 09:45:13 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-10-06 16:55:44 +0900 |
commit | d15b38d944c27cb627741206d8adf285153a4df2 (patch) | |
tree | 6f772fb0739ac7b4ccf26ceb43085cca896de2b8 | |
parent | 3e84290213a86eff5e50ddf92a9b136a5034ac05 (diff) |
[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
-rw-r--r-- | lib/open-uri.rb | 14 | ||||
-rw-r--r-- | 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 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 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 } 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 |