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

ruby-changes:28358

From: charliesome <ko1@a...>
Date: Mon, 22 Apr 2013 22:57:33 +0900 (JST)
Subject: [ruby-changes:28358] charliesome:r40410 (trunk): * insns.def (opt_mod): Use % operator if both operands are positive for

charliesome	2013-04-22 22:57:21 +0900 (Mon, 22 Apr 2013)

  New Revision: 40410

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

  Log:
    * insns.def (opt_mod): Use % operator if both operands are positive for
      a significant performance improvement. Thanks to @samsaffron.

  Modified files:
    trunk/ChangeLog
    trunk/insns.def

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40409)
+++ ChangeLog	(revision 40410)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Apr 22 22:54:00 2013  Charlie Somerville  <charlie@c...>
+
+	* insns.def (opt_mod): Use % operator if both operands are positive for
+	  a significant performance improvement. Thanks to @samsaffron.
+
 Mon Apr 22 17:09:37 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* marshal.c (r_object0): copy all instance variables not only generic
Index: insns.def
===================================================================
--- insns.def	(revision 40409)
+++ insns.def	(revision 40410)
@@ -1524,13 +1524,15 @@ opt_mod https://github.com/ruby/ruby/blob/trunk/insns.def#L1524
 {
     if (FIXNUM_2_P(recv, obj) &&
 	BASIC_OP_UNREDEFINED_P(BOP_MOD, FIXNUM_REDEFINED_OP_FLAG )) {
-	long x, y, mod;
+	long x, y;
 
 	x = FIX2LONG(recv);
 	y = FIX2LONG(obj);
-	{
+	if (x > 0 && y > 0) {
+	    val = LONG2FIX(x % y);
+	} else {
 	    /* copied from numeric.c#fixdivmod */
-	    long div;
+	    long div, mod;
 
 	    if (y == 0)
 		rb_num_zerodiv();
@@ -1551,8 +1553,8 @@ opt_mod https://github.com/ruby/ruby/blob/trunk/insns.def#L1553
 		mod += y;
 		div -= 1;
 	    }
+	    val = LONG2FIX(mod);
 	}
-	val = LONG2FIX(mod);
     }
     else if (FLONUM_2_P(recv, obj) &&
 	     BASIC_OP_UNREDEFINED_P(BOP_MOD, FLOAT_REDEFINED_OP_FLAG)) {

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

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