Forum: Ruby-dev Fwd: glass:r37420 (trunk): * array.c (recursive_equal): performance improvement.

308cbef6e86dfc49cce3b2d4cf42aedc?d=identicon&s=25 SASADA Koichi (Guest)
on 2012-11-02 15:06
(Received via mailing list)
Attachment: ________ (0 Bytes)
ChangeLog
$B$H%m%0$K!$;2>H$O$"$k$s$G$9$,!$$I$&@-G=8~>e$7$?$N$+!$C;$/$^$H$a(B
$B$FD:$1$k$HNI$$$+$H;W$$$^$9!%(B


-------- Original Message --------
Subject: [ruby-changes:25363] glass:r37420 (trunk): * array.c
(recursive_equal): performance improvement.
Date: Fri,  2 Nov 2012 16:04:58 +0900 (JST)
From: glass <ko1@atdot.net>
Reply-To: ruby-changes@quickml.atdot.net
To: ruby-changes@quickml.atdot.net

glass  2012-11-02 16:04:39 +0900 (Fri, 02 Nov 2012)

  New Revision: 37420

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=r...

  Log:
    * array.c (recursive_equal): performance improvement.
    [ruby-dev:45412] [Feature #6177]

  Modified files:
    trunk/ChangeLog
    trunk/array.c

Index: array.c
===================================================================
--- array.c  (revision 37419)
+++ array.c  (revision 37420)
@@ -3270,11 +3270,27 @@
 recursive_equal(VALUE ary1, VALUE ary2, int recur)
 {
     long i;
+    VALUE *p1, *p2;

     if (recur) return Qtrue; /* Subtle! */
-    for (i=0; i<RARRAY_LEN(ary1); i++) {
-  if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
-      return Qfalse;
+
+    p1 = RARRAY_PTR(ary1);
+    p2 = RARRAY_PTR(ary2);
+
+    for (i = 0; i < RARRAY_LEN(ary1); i++) {
+  if (*p1 != *p2) {
+      if (rb_equal(*p1, *p2)) {
+    if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2))
+        return Qfalse;
+    p1 = RARRAY_PTR(ary1) + i;
+    p2 = RARRAY_PTR(ary2) + i;
+      }
+      else {
+    return Qfalse;
+      }
+  }
+  p1++;
+  p2++;
     }
     return Qtrue;
 }
Index: ChangeLog
===================================================================
--- ChangeLog  (revision 37419)
+++ ChangeLog  (revision 37420)
@@ -1,3 +1,8 @@
+Fri Nov  2 14:52:52 2012  Masaki Matsushita <glass.saga@gmail.com>
+
+  * array.c (recursive_equal): performance improvement.
+    [ruby-dev:45412] [Feature #6177]
+
 Fri Nov  2 14:47:53 2012  Shugo Maeda  <shugo@ruby-lang.org>

   * string.c (sym_to_proc, sym_call): A Proc created by Symbol#to_proc
C042517d59bed4761cc88681bf71fca8?d=identicon&s=25 Masaki Matsushita (Guest)
on 2012-11-02 16:41
(Received via mailing list)
2012/11/2 SASADA Koichi <ko1@atdot.net>:
> ChangeLog とログに,参照はあるんですが,どう性能向上したのか,短くまとめ
> て頂けると良いかと思います.

ご指摘ありがとうございます。
短いですがChangeLogに説明を追加してコミットしました。
今後は簡潔な説明をつけるよう気をつけます。
This topic is locked and can not be replied to.