diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-04-29 11:58:12 -0700 |
---|---|---|
committer | usa <usa@garbagecollect.jp> | 2021-07-31 21:27:21 +0900 |
commit | 2a7235421fcd59b449c84306d059f22b4c5f0865 (patch) | |
tree | d79b10a25db41b4be2ccdb0db09f30f9b2c5c425 | |
parent | 4b371d6ab28f9c0f041af01f76a9bcedaeeee917 (diff) | |
download | ruby-2a7235421fcd59b449c84306d059f22b4c5f0865.tar.gz |
Fix SortedSet not being sorted the first time when rbtree is used
Fixes [Bug #17841]
-rw-r--r-- | lib/set.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/set.rb b/lib/set.rb index 5a96c81832..1b0e3ae6fc 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -691,6 +691,7 @@ class SortedSet < Set def setup # :nodoc: @@setup and return + ret = nil @@mutex.synchronize do # a hack to shut up warning @@ -698,6 +699,7 @@ class SortedSet < Set begin require 'rbtree' + ret = :rbtree module_eval <<-END, __FILE__, __LINE__+1 def initialize(*args) @@ -712,6 +714,7 @@ class SortedSet < Set alias << add END rescue LoadError + ret = true module_eval <<-END, __FILE__, __LINE__+1 def initialize(*args) @keys = nil @@ -788,13 +791,17 @@ class SortedSet < Set remove_method :old_init @@setup = true + ret end end end def initialize(*args, &block) # :nodoc: - SortedSet.setup - @keys = nil + if SortedSet.setup == :rbtree + @hash = RBTree.new + else + @keys = nil + end super end end |