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_uminus, bigsub_int): use BIGNUM_NEGATE. * internal.h (BIGNUM_NEGATE): simplify negation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
174be80027
commit
49079911ba
2 changed files with 4 additions and 3 deletions
6
bignum.c
6
bignum.c
|
@ -5526,7 +5526,7 @@ rb_big_uminus(VALUE x)
|
|||
{
|
||||
VALUE z = rb_big_clone(x);
|
||||
|
||||
BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
|
||||
BIGNUM_NEGATE(z);
|
||||
|
||||
return bignorm(z);
|
||||
}
|
||||
|
@ -5624,7 +5624,7 @@ bigsub_int(VALUE x, long y0)
|
|||
assert(xn == zn);
|
||||
num = (BDIGIT_DBL_SIGNED)xds[0] - y;
|
||||
if (xn == 1 && num < 0) {
|
||||
BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
|
||||
BIGNUM_NEGATE(z);
|
||||
zds[0] = (BDIGIT)-num;
|
||||
RB_GC_GUARD(x);
|
||||
return bignorm(z);
|
||||
|
@ -5687,7 +5687,7 @@ bigsub_int(VALUE x, long y0)
|
|||
assert(num == 0 || num == -1);
|
||||
if (num < 0) {
|
||||
get2comp(z);
|
||||
BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
|
||||
BIGNUM_NEGATE(z);
|
||||
}
|
||||
RB_GC_GUARD(x);
|
||||
return bignorm(z);
|
||||
|
|
|
@ -364,6 +364,7 @@ struct RBignum {
|
|||
: (RBASIC(b)->flags &= ~BIGNUM_SIGN_BIT))
|
||||
#define BIGNUM_POSITIVE_P(b) BIGNUM_SIGN(b)
|
||||
#define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b))
|
||||
#define BIGNUM_NEGATE(b) (RBASIC(b)->flags ^= BIGNUM_SIGN_BIT)
|
||||
|
||||
#define BIGNUM_EMBED_FLAG FL_USER2
|
||||
#define BIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
|
||||
|
|
Loading…
Reference in a new issue