diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-20 10:09:14 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-20 10:09:14 +0000 |
commit | 57638377cc22ed7b677f9826f79988ffb9451e5a (patch) | |
tree | d52e358482920ab843d87eee5c7568263265094e | |
parent | be05c5798fd73c951228eeac95b0e164a2aed142 (diff) | |
download | ruby-57638377cc22ed7b677f9826f79988ffb9451e5a.tar.gz |
bignum.c: micro optimization
* bignum.c (rb_big_cmp): micro optimization of Fixnum comparison.
as SIGNED_VALUE and Fixnum have same sign-bits and same order.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | bignum.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -5291,8 +5291,11 @@ rb_big_cmp(VALUE x, VALUE y) if (FIXNUM_P(y)) { x = bigfixize(x); if (FIXNUM_P(x)) { - if (FIX2LONG(x) < FIX2LONG(y)) return INT2FIX(-1); - return INT2FIX(FIX2LONG(x) > FIX2LONG(y)); + /* SIGNED_VALUE and Fixnum have same sign-bits, same + * order */ + SIGNED_VALUE sx = (SIGNED_VALUE)x, sy = (SIGNED_VALUE)y; + if (sx < sy) return INT2FIX(-1); + return INT2FIX(sx > sy); } } else if (RB_BIGNUM_TYPE_P(y)) { |