ruby-changes:29409
From: akr <ko1@a...>
Date: Thu, 20 Jun 2013 08:09:15 +0900 (JST)
Subject: [ruby-changes:29409] akr:r41461 (trunk): * bignum.c (BIGSIZE): New macro.
akr 2013-06-20 08:09:05 +0900 (Thu, 20 Jun 2013) New Revision: 41461 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41461 Log: * bignum.c (BIGSIZE): New macro. (bigfixize): Use BIGSIZE. (big2ulong): Ditto. (check_shiftdown): Ditto. (rb_big_aref): Ditto. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41460) +++ ChangeLog (revision 41461) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jun 20 08:07:23 2013 Tanaka Akira <akr@f...> + + * bignum.c (BIGSIZE): New macro. + (bigfixize): Use BIGSIZE. + (big2ulong): Ditto. + (check_shiftdown): Ditto. + (rb_big_aref): Ditto. + Thu Jun 20 07:46:48 2013 Masaya Tarui <tarui@r...> * gc.c (rb_gc_writebarrier): give up rescan A and register B directly Index: bignum.c =================================================================== --- bignum.c (revision 41460) +++ bignum.c (revision 41461) @@ -51,6 +51,10 @@ static VALUE big_three = Qnil; https://github.com/ruby/ruby/blob/trunk/bignum.c#L51 #define BIGZEROP(x) (RBIGNUM_LEN(x) == 0 || \ (BDIGITS(x)[0] == 0 && \ (RBIGNUM_LEN(x) == 1 || bigzero_p(x)))) +#define BIGSIZE(x) (RBIGNUM_LEN(x) == 0 ? (size_t)0 : \ + BDIGITS(x)[RBIGNUM_LEN(x)-1] ? \ + (size_t)(RBIGNUM_LEN(x)*SIZEOF_BDIGITS - nlz(BDIGITS(x)[RBIGNUM_LEN(x)-1])/CHAR_BIT) : \ + rb_absint_size(x, NULL)) #define BIGDIVREM_EXTRA_WORDS 2 #define roomof(n, m) ((int)(((n)+(m)-1) / (m))) @@ -293,7 +297,7 @@ bigfixize(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L297 BDIGIT *ds = BDIGITS(x); if (len == 0) return INT2FIX(0); - if (rb_absint_size(x, NULL) <= sizeof(long)) { + if (BIGSIZE(x) <= sizeof(long)) { long num = 0; #if SIZEOF_BDIGITS >= SIZEOF_LONG num = (long)ds[0]; @@ -2253,7 +2257,7 @@ big2ulong(VALUE x, const char *type, int https://github.com/ruby/ruby/blob/trunk/bignum.c#L2257 BDIGIT_DBL num; BDIGIT *ds; - if (rb_absint_size(x, NULL) > sizeof(long)) { + if (BIGSIZE(x) > sizeof(long)) { if (check) rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type); len = bdigit_roomof(sizeof(long)); @@ -4684,7 +4688,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/bignum.c#L4688 check_shiftdown(VALUE y, VALUE x) { if (!RBIGNUM_LEN(x)) return INT2FIX(0); - if (rb_absint_size(y, NULL) > SIZEOF_LONG) { + if (BIGSIZE(y) > SIZEOF_LONG) { return RBIGNUM_SIGN(x) ? INT2FIX(0) : INT2FIX(-1); } return Qnil; @@ -4886,7 +4890,7 @@ rb_big_aref(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4890 if (!RBIGNUM_SIGN(y)) return INT2FIX(0); bigtrunc(y); - if (rb_absint_size(y, NULL) > sizeof(long)) { + if (BIGSIZE(y) > sizeof(long)) { out_of_range: return RBIGNUM_SIGN(x) ? INT2FIX(0) : INT2FIX(1); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/