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

* bignum.c (rb_big_cmp): Specialize a comparison to zero.

* ext/bigdecimal/bigdecimal.c (is_negative): Use rb_big_cmp instead of
  RBIGNUM_NEGATIVE_P.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-02-11 14:43:23 +00:00
parent ab67419b75
commit c1de2f4e3a
3 changed files with 14 additions and 2 deletions

View file

@ -1,3 +1,10 @@
Tue Feb 11 23:42:27 2014 Tanaka Akira <akr@fsij.org>
* bignum.c (rb_big_cmp): Specialize a comparison to zero.
* ext/bigdecimal/bigdecimal.c (is_negative): Use rb_big_cmp instead of
RBIGNUM_NEGATIVE_P.
Tue Feb 11 22:59:10 2014 Tanaka Akira <akr@fsij.org>
* ext/openssl/ossl_bn.c (ossl_bn_initialize): Use rb_integer_pack.

View file

@ -5395,7 +5395,12 @@ rb_big_cmp(VALUE x, VALUE y)
{
int cmp;
if (FIXNUM_P(y)) {
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));
}
else if (RB_BIGNUM_TYPE_P(y)) {

View file

@ -2095,7 +2095,7 @@ is_negative(VALUE x)
return FIX2LONG(x) < 0;
}
else if (RB_TYPE_P(x, T_BIGNUM)) {
return RBIGNUM_NEGATIVE_P(x);
return FIX2INT(rb_big_cmp(x, INT2FIX(0))) < 0;
}
else if (RB_TYPE_P(x, T_FLOAT)) {
return RFLOAT_VALUE(x) < 0.0;