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

ruby-changes:42139

From: naruse <ko1@a...>
Date: Mon, 21 Mar 2016 22:17:51 +0900 (JST)
Subject: [ruby-changes:42139] naruse:r54213 (trunk): * time.c (mod): Add Fixnum case.

naruse	2016-03-21 22:17:45 +0900 (Mon, 21 Mar 2016)

  New Revision: 54213

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54213

  Log:
    * time.c (mod): Add Fixnum case.
    
    * time.c (quo): c can be Fixnum except a == FIXNUM_MIN && b == -1.
      Such case can be optimized out because quo()'s argument is constant.

  Modified files:
    trunk/ChangeLog
    trunk/time.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54212)
+++ ChangeLog	(revision 54213)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Mar 21 22:15:11 2016  NARUSE, Yui  <naruse@r...>
+
+	* time.c (mod): Add Fixnum case.
+
+	* time.c (quo): c can be Fixnum except a == FIXNUM_MIN && b == -1.
+	  Such case can be optimized out because quo()'s argument is constant.
+
 Mon Mar 21 22:09:24 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* internal.h (rb_fix_mul_fix): multiply converted values, not
Index: time.c
===================================================================
--- time.c	(revision 54212)
+++ time.c	(revision 54213)
@@ -107,10 +107,12 @@ mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/time.c#L107
 static VALUE
 mod(VALUE x, VALUE y)
 {
-    switch (TYPE(x)) {
-      case T_BIGNUM: return rb_big_modulo(x, y);
-      default: return rb_funcall(x, '%', 1, y);
+    if (FIXNUM_P(y)) {
+	if (FIX2LONG(y) == 0) rb_num_zerodiv();
+	if (FIXNUM_P(x)) return LONG2FIX(rb_mod(FIX2LONG(x), FIX2LONG(y)));
     }
+    if (RB_TYPE_P(x, T_BIGNUM)) return rb_big_modulo(x, y);
+    return rb_funcall(x, '%', 1, y);
 }
 
 #define neg(x) (sub(INT2FIX(0), (x)))
@@ -124,9 +126,10 @@ quo(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/time.c#L126
         a = FIX2LONG(x);
         b = FIX2LONG(y);
         if (b == 0) rb_num_zerodiv();
+        if (a == FIXNUM_MIN && b == -1) LONG2NUM(-a);
         c = a / b;
-        if (c * b == a) {
-            return LONG2NUM(c);
+        if (a % b == 0) {
+            return LONG2FIX(c);
         }
     }
     ret = rb_funcall(x, id_quo, 1, y);

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

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