summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-20 10:09:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-20 10:09:14 +0000
commit57638377cc22ed7b677f9826f79988ffb9451e5a (patch)
treed52e358482920ab843d87eee5c7568263265094e /bignum.c
parentbe05c5798fd73c951228eeac95b0e164a2aed142 (diff)
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
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bignum.c b/bignum.c
index 0db06042d5..a19d2b90ea 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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)) {