summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-13 19:09:36 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-13 19:09:36 +0000
commit6ad786c3c93cffb7d78eff58d7cb11dcf2440ef9 (patch)
treea04c78e2258772a07ab83c29d6783d0a12fc86de /lib
parent0efe5cce4cf608a16663dbb3c5a80017c0b70e64 (diff)
downloadruby-6ad786c3c93cffb7d78eff58d7cb11dcf2440ef9.tar.gz
ruby-6ad786c3c93cffb7d78eff58d7cb11dcf2440ef9.tar.xz
ruby-6ad786c3c93cffb7d78eff58d7cb11dcf2440ef9.zip
* lib/set.rb (==): Optimization; patch by Arthur Schreiber [ruby-core:17203]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/set.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/set.rb b/lib/set.rb
index 8f2bef91b..f21ff14a7 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -327,13 +327,16 @@ class Set
# Returns true if two sets are equal. The equality of each couple
# of elements is defined according to Object#eql?.
- def ==(set)
- equal?(set) and return true
-
- set.is_a?(Set) && size == set.size or return false
-
- hash = @hash.dup
- set.all? { |o| hash.include?(o) }
+ def ==(other)
+ if self.equal?(other)
+ true
+ elsif other.instance_of?(self.class)
+ @hash == other.instance_variable_get(:@hash)
+ elsif other.is_a?(Set) && self.size == other.size
+ other.all? { |o| @hash.include?(o) }
+ else
+ false
+ end
end
def hash # :nodoc: