@@ -16,7 +16,6 @@ module URI
16
16
REGEXP = RFC2396_REGEXP
17
17
Parser = RFC2396_Parser
18
18
RFC3986_PARSER = RFC3986_Parser . new
19
- Ractor . make_shareable ( RFC3986_PARSER ) if defined? ( Ractor )
20
19
21
20
# URI::Parser.new
22
21
DEFAULT_PARSER = Parser . new
@@ -28,7 +27,6 @@ module URI
28
27
DEFAULT_PARSER . regexp . each_pair do |sym , str |
29
28
const_set ( sym , str )
30
29
end
31
- Ractor . make_shareable ( DEFAULT_PARSER ) if defined? ( Ractor )
32
30
33
31
module Util # :nodoc:
34
32
def make_components_hash ( klass , array_hash )
@@ -64,38 +62,22 @@ def make_components_hash(klass, array_hash)
64
62
65
63
include REGEXP
66
64
67
- SCHEME_LIST_MUTEX = Mutex . new
68
- private_constant :SCHEME_LIST_MUTEX
69
-
65
+ @@schemes = { }
70
66
# Returns a Hash of the defined schemes.
71
- # The list is lazily calculated.
72
67
def self . scheme_list
73
- return const_get ( :SCHEMES ) if defined? ( SCHEMES )
74
-
75
- SCHEME_LIST_MUTEX . synchronize do
76
- const_set ( :SCHEMES , ObjectSpace .
77
- each_object ( Class ) .
78
- select { |klass | klass < URI ::Generic } .
79
- each_with_object ( { } ) { |klass , acc | acc [ klass . name . split ( '::' ) . last . upcase ] = klass } .
80
- freeze )
81
- end
82
- end
83
-
84
- # Re-calculate scheme list
85
- def self . refresh_scheme_list
86
- SCHEME_LIST_MUTEX . synchronize do
87
- remove_const ( :SCHEMES ) if defined? ( SCHEMES )
88
- end
89
-
90
- scheme_list
68
+ @@schemes
91
69
end
92
70
93
71
#
94
72
# Construct a URI instance, using the scheme to detect the appropriate class
95
73
# from +URI.scheme_list+.
96
74
#
97
75
def self . for ( scheme , *arguments , default : Generic )
98
- uri_class = scheme_list [ scheme . to_s . upcase ] || default
76
+ if scheme
77
+ uri_class = @@schemes [ scheme . upcase ] || default
78
+ else
79
+ uri_class = default
80
+ end
99
81
100
82
return uri_class . new ( scheme , *arguments )
101
83
end
0 commit comments