summaryrefslogtreecommitdiff
path: root/lib/uri/common.rb
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2021-06-25 13:24:56 +0200
committerHiroshi SHIBATA <[email protected]>2021-07-27 16:54:26 +0900
commit090d799c2496f4c0e1f25c9970f4015fc693ff0e (patch)
tree3a96ecfaa033b158655be52d1df4eb4b8f56264b /lib/uri/common.rb
parenta288c21a5d46418e75c0f03eb12ff0782e51568d (diff)
[ruby/uri] Revert "Fix to support Ruby 3.0 Ractor"
* This reverts commit 1faa4fdc161d7aeebdb5de0c407b923beaecf898. * It has too many problems, see https://github.com/ruby/uri/pull/22 for discussion. https://github.com/ruby/uri/commit/b959da2dc9
Diffstat (limited to 'lib/uri/common.rb')
-rw-r--r--lib/uri/common.rb32
1 files changed, 7 insertions, 25 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index ab3234cb37..915c0e9519 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -16,7 +16,6 @@ module URI
REGEXP = RFC2396_REGEXP
Parser = RFC2396_Parser
RFC3986_PARSER = RFC3986_Parser.new
- Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor)
# URI::Parser.new
DEFAULT_PARSER = Parser.new
@@ -28,7 +27,6 @@ module URI
DEFAULT_PARSER.regexp.each_pair do |sym, str|
const_set(sym, str)
end
- Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor)
module Util # :nodoc:
def make_components_hash(klass, array_hash)
@@ -64,30 +62,10 @@ module URI
include REGEXP
- SCHEME_LIST_MUTEX = Mutex.new
- private_constant :SCHEME_LIST_MUTEX
-
+ @@schemes = {}
# Returns a Hash of the defined schemes.
- # The list is lazily calculated.
def self.scheme_list
- return const_get(:SCHEMES) if defined?(SCHEMES)
-
- SCHEME_LIST_MUTEX.synchronize do
- const_set(:SCHEMES, ObjectSpace.
- each_object(Class).
- select { |klass| klass < URI::Generic }.
- each_with_object({}) { |klass, acc| acc[klass.name.split('::').last.upcase] = klass }.
- freeze)
- end
- end
-
- # Re-calculate scheme list
- def self.refresh_scheme_list
- SCHEME_LIST_MUTEX.synchronize do
- remove_const(:SCHEMES) if defined?(SCHEMES)
- end
-
- scheme_list
+ @@schemes
end
#
@@ -95,7 +73,11 @@ module URI
# from +URI.scheme_list+.
#
def self.for(scheme, *arguments, default: Generic)
- uri_class = scheme_list[scheme.to_s.upcase] || default
+ if scheme
+ uri_class = @@schemes[scheme.upcase] || default
+ else
+ uri_class = default
+ end
return uri_class.new(scheme, *arguments)
end