[前][次][番号順一覧][スレッド一覧]

ruby-changes:13158

From: marcandre <ko1@a...>
Date: Mon, 14 Sep 2009 04:09:52 +0900 (JST)
Subject: [ruby-changes:13158] Ruby:r24910 (trunk): * lib/set.rb (==): Optimization; patch by Arthur Schreiber

marcandre	2009-09-14 04:09:36 +0900 (Mon, 14 Sep 2009)

  New Revision: 24910

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24910

  Log:
    * lib/set.rb (==): Optimization; patch by Arthur Schreiber [ruby-core:17203]

  Modified files:
    trunk/ChangeLog
    trunk/lib/set.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24909)
+++ ChangeLog	(revision 24910)
@@ -1,3 +1,7 @@
+Mon Sep 14 04:07:09 2009  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* lib/set.rb (==): Optimization; patch by Arthur Schreiber [ruby-core:17203]
+
 Mon Sep 14 03:30:23 2009  Alexander Zavorine  <alexandre.zavorine@n...>
 
 	* symbian/pre-build: added rule to generate id.h for Symbian build.
Index: lib/set.rb
===================================================================
--- lib/set.rb	(revision 24909)
+++ lib/set.rb	(revision 24910)
@@ -327,13 +327,16 @@
 
   # 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:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]