diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-20 09:53:50 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-20 09:53:50 +0000 |
commit | 94f28031275153924496e6ffe41d3e5431a8ffea (patch) | |
tree | 996c1366d33af40280a96b8c477594a3c0ccd653 | |
parent | 86a4ef44e954126825adc49ee40d22f165f5d831 (diff) | |
download | ruby-94f28031275153924496e6ffe41d3e5431a8ffea.tar.gz |
numeric.c: optimize Fixnum<->Bignum comparisons
* numeric.c (fix_gt, fix_ge, fix_lt, fix_le): optimize comparisons
Fixnum against Bignum by rb_big_cmp in inversed order without
new Bignum instance.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | numeric.c | 8 |
2 files changed, 10 insertions, 4 deletions
@@ -1,3 +1,9 @@ +Sun Mar 20 18:53:49 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * numeric.c (fix_gt, fix_ge, fix_lt, fix_le): optimize comparisons + Fixnum against Bignum by rb_big_cmp in inversed order without + new Bignum instance. + Sun Mar 20 18:44:52 2016 NARUSE, Yui <naruse@ruby-lang.org> * time.c (add): remove FIXABLE() which is in LONG2NUM(). @@ -3482,7 +3482,7 @@ fix_gt(VALUE x, VALUE y) return Qfalse; } else if (RB_TYPE_P(y, T_BIGNUM)) { - return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) > 0 ? Qtrue : Qfalse; + return rb_big_cmp(y, x) == INT2FIX(-1) ? Qtrue : Qfalse; } else if (RB_TYPE_P(y, T_FLOAT)) { return rb_integer_float_cmp(x, y) == INT2FIX(1) ? Qtrue : Qfalse; @@ -3508,7 +3508,7 @@ fix_ge(VALUE x, VALUE y) return Qfalse; } else if (RB_TYPE_P(y, T_BIGNUM)) { - return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) >= 0 ? Qtrue : Qfalse; + return rb_big_cmp(y, x) != INT2FIX(+1) ? Qtrue : Qfalse; } else if (RB_TYPE_P(y, T_FLOAT)) { VALUE rel = rb_integer_float_cmp(x, y); @@ -3534,7 +3534,7 @@ fix_lt(VALUE x, VALUE y) return Qfalse; } else if (RB_TYPE_P(y, T_BIGNUM)) { - return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) < 0 ? Qtrue : Qfalse; + return rb_big_cmp(y, x) == INT2FIX(+1) ? Qtrue : Qfalse; } else if (RB_TYPE_P(y, T_FLOAT)) { return rb_integer_float_cmp(x, y) == INT2FIX(-1) ? Qtrue : Qfalse; @@ -3560,7 +3560,7 @@ fix_le(VALUE x, VALUE y) return Qfalse; } else if (RB_TYPE_P(y, T_BIGNUM)) { - return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) <= 0 ? Qtrue : Qfalse; + return rb_big_cmp(y, x) != INT2FIX(-1) ? Qtrue : Qfalse; } else if (RB_TYPE_P(y, T_FLOAT)) { VALUE rel = rb_integer_float_cmp(x, y); |