ruby-changes:53538
From: shyouhei <ko1@a...>
Date: Fri, 16 Nov 2018 12:09:06 +0900 (JST)
Subject: [ruby-changes:53538] shyouhei:r65754 (trunk): bignum.c: avoid (size_t)--
shyouhei 2018-11-16 12:09:00 +0900 (Fri, 16 Nov 2018) New Revision: 65754 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65754 Log: bignum.c: avoid (size_t)-- Modified files: trunk/bignum.c Index: bignum.c =================================================================== --- bignum.c (revision 65753) +++ bignum.c (revision 65754) @@ -385,6 +385,7 @@ bdigitdbl2bary(BDIGIT *ds, size_t n, BDI https://github.com/ruby/ruby/blob/trunk/bignum.c#L385 static int bary_cmp(const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn) { + size_t i; BARY_TRUNC(xds, xn); BARY_TRUNC(yds, yn); @@ -393,11 +394,12 @@ bary_cmp(const BDIGIT *xds, size_t xn, c https://github.com/ruby/ruby/blob/trunk/bignum.c#L394 if (xn > yn) return 1; - while (xn-- && xds[xn] == yds[xn]) - ; - if (xn == (size_t)-1) + for (i = 0; i < xn; i++) + if (xds[xn - i - 1] != yds[yn - i - 1]) + break; + if (i == xn) return 0; - return xds[xn] < yds[xn] ? -1 : 1; + return xds[xn - i - 1] < yds[yn - i - 1] ? -1 : 1; } static BDIGIT @@ -5152,6 +5154,9 @@ rb_big2long(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5154 static unsigned LONG_LONG big2ull(VALUE x, const char *type) { +#if SIZEOF_LONG_LONG > SIZEOF_BDIGIT + size_t i; +#endif size_t len = BIGNUM_LEN(x); unsigned LONG_LONG num; BDIGIT *ds = BDIGITS(x); @@ -5164,9 +5169,9 @@ big2ull(VALUE x, const char *type) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5169 num = (unsigned LONG_LONG)ds[0]; #else num = 0; - while (len--) { + for (i = 0; i < len; i++) { num = BIGUP(num); - num += ds[len]; + num += ds[len - i - 1]; } #endif return num; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/