[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
This commit is contained in:
parent
3e84290213
commit
d15b38d944
@ -410,6 +410,13 @@ module OpenURI
|
|||||||
end
|
end
|
||||||
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.
|
# Mixin for holding meta-information.
|
||||||
module Meta
|
module Meta
|
||||||
def Meta.init(obj, src=nil) # :nodoc:
|
def Meta.init(obj, src=nil) # :nodoc:
|
||||||
@ -487,13 +494,6 @@ module OpenURI
|
|||||||
end
|
end
|
||||||
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:
|
def content_type_parse # :nodoc:
|
||||||
vs = @metas['content-type']
|
vs = @metas['content-type']
|
||||||
# The last (?:;#{RE_LWS}?)? matches extra ";" which violates RFC2045.
|
# The last (?:;#{RE_LWS}?)? matches extra ";" which violates RFC2045.
|
||||||
|
@ -902,5 +902,13 @@ class TestOpenURI < Test::Unit::TestCase
|
|||||||
}
|
}
|
||||||
end
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user