aboutsummaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-21 13:17:45 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-21 13:17:45 +0000
commit2398e8ad95f5fa73c63f56d6180daebcacf1d1d5 (patch)
tree7a3915a772d30e84e4aac440e208308fd228cadc /time.c
parent6e60d2cee8ea6f1037bbbda9a7d9e3090cfd95b4 (diff)
downloadruby-2398e8ad95f5fa73c63f56d6180daebcacf1d1d5.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/time.c b/time.c
index 908ad2fcd1..b725190780 100644
--- a/time.c
+++ b/time.c
@@ -107,10 +107,12 @@ mul(VALUE x, VALUE y)
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)
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);