1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2016-03-20 10:09:14 +00:00
parent be05c5798f
commit 57638377cc

View file

@ -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)) {