diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-15 02:48:44 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-15 02:48:44 +0000 |
commit | dfd26e3a473aa76fce20dc1359b0c4ab1d88eea9 (patch) | |
tree | 3d88db763f1028b07b5a10309e557bd76078ecf5 /bignum.c | |
parent | f9810d26b10c44b5fcdf07b886792c6a0b7c107f (diff) | |
download | ruby-dfd26e3a473aa76fce20dc1359b0c4ab1d88eea9.tar.gz |
* bignum.c (rb_big_cmp): Avoid bignum allocation for comparison
between bignum and fixnum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -5277,13 +5277,17 @@ rb_big_cmp(VALUE x, VALUE y) { int cmp; - if (y == INT2FIX(0)) { - if (BIGZEROP(x)) return INT2FIX(0); - if (RBIGNUM_NEGATIVE_P(x)) return INT2FIX(-1); - return INT2FIX(1); - } - else if (FIXNUM_P(y)) { - y = rb_int2big(FIX2LONG(y)); + if (FIXNUM_P(y)) { + x = bignorm(x); + if (FIXNUM_P(x)) { + if (FIX2LONG(x) > FIX2LONG(y)) return INT2FIX(1); + if (FIX2LONG(x) < FIX2LONG(y)) return INT2FIX(-1); + return INT2FIX(0); + } + else { + if (RBIGNUM_NEGATIVE_P(x)) return INT2FIX(-1); + return INT2FIX(1); + } } else if (RB_BIGNUM_TYPE_P(y)) { } |