ruby-changes:29631
From: akr <ko1@a...>
Date: Fri, 28 Jun 2013 08:08:10 +0900 (JST)
Subject: [ruby-changes:29631] akr:r41683 (trunk): * bignum.c (bigand_int): Add arguments, xn and hibitsx.
akr 2013-06-28 08:07:59 +0900 (Fri, 28 Jun 2013) New Revision: 41683 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41683 Log: * bignum.c (bigand_int): Add arguments, xn and hibitsx. Use twocomp2abs_bang. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41682) +++ ChangeLog (revision 41683) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Jun 28 08:06:22 2013 Tanaka Akira <akr@f...> + + * bignum.c (bigand_int): Add arguments, xn and hibitsx. + Use twocomp2abs_bang. + Thu Jun 27 23:58:13 2013 Tanaka Akira <akr@f...> * bignum.c (abs2twocomp_bang): Removed. Index: bignum.c =================================================================== --- bignum.c (revision 41682) +++ bignum.c (revision 41683) @@ -4653,30 +4653,32 @@ rb_big_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4653 } static VALUE -bigand_int(VALUE x, long y) +bigand_int(VALUE x, long xn, BDIGIT hibitsx, long y) { VALUE z; BDIGIT *xds, *zds; - long xn, zn; + long zn; long i; - char sign; + BDIGIT hibitsy; if (y == 0) return INT2FIX(0); - sign = (y > 0); + if (xn == 0) return LONG2NUM((long)(hibitsx & y)); + hibitsy = 0 <= y ? 0 : BDIGMAX; xds = BDIGITS(x); - zn = xn = RBIGNUM_LEN(x); #if SIZEOF_BDIGITS >= SIZEOF_LONG - if (sign) { + if (!hibitsy) { y &= xds[0]; return LONG2NUM(y); } #endif + + zn = xn; #if SIZEOF_BDIGITS < SIZEOF_LONG - if (RBIGNUM_NEGATIVE_P(x) && zn < bdigit_roomof(SIZEOF_LONG)) + if (hibitsx && zn < bdigit_roomof(SIZEOF_LONG)) zn = bdigit_roomof(SIZEOF_LONG); #endif - z = bignew(zn, RBIGNUM_SIGN(x) || sign); + z = bignew(zn, 0); zds = BDIGITS(z); #if SIZEOF_BDIGITS >= SIZEOF_LONG @@ -4690,18 +4692,18 @@ bigand_int(VALUE x, long y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4692 } for (; i < zn; i++) { if (y == 0 || y == -1) break; - zds[i] = RBIGNUM_NEGATIVE_P(x) ? BIGLO(y) : 0; + zds[i] = hibitsx & BIGLO(y); y = BIGDN(y); } - #endif for (;i < xn; i++) { - zds[i] = sign?0:xds[i]; + zds[i] = xds[i] & hibitsy; } for (;i < zn; i++) { - zds[i] = (!sign && RBIGNUM_NEGATIVE_P(x)) ? BDIGMAX : 0; + zds[i] = hibitsx & hibitsy; } - if (!RBIGNUM_SIGN(z)) get2comp(z); + twocomp2abs_bang(z, hibitsx && hibitsy); + RB_GC_GUARD(x); return bignorm(z); } @@ -4730,7 +4732,7 @@ rb_big_and(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4732 hibitsx = abs2twocomp(&x, &xl); if (FIXNUM_P(y)) { - return bigand_int(x, FIX2LONG(y)); + return bigand_int(x, xl, hibitsx, FIX2LONG(y)); } hibitsy = abs2twocomp(&y, &yl); if (xl > yl) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/