ruby-changes:30249
From: akr <ko1@a...>
Date: Thu, 1 Aug 2013 06:33:36 +0900 (JST)
Subject: [ruby-changes:30249] akr:r42301 (trunk): * bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now.
akr 2013-08-01 06:33:14 +0900 (Thu, 01 Aug 2013) New Revision: 42301 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42301 Log: * bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now. (big2str_struct): Two fields added: hbase2, hbase2_numdigits. (rb_big2str1): Initialize above fields. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42300) +++ ChangeLog (revision 42301) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Aug 1 06:28:48 2013 Tanaka Akira <akr@f...> + + * bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now. + (big2str_struct): Two fields added: hbase2, hbase2_numdigits. + (rb_big2str1): Initialize above fields. + Thu Aug 1 04:06:17 2013 Nobuyoshi Nakada <nobu@r...> * lib/rdoc/options.rb (RDoc#finish): include root path in include Index: bignum.c =================================================================== --- bignum.c (revision 42300) +++ bignum.c (revision 42301) @@ -4216,6 +4216,8 @@ struct big2str_struct { https://github.com/ruby/ruby/blob/trunk/bignum.c#L4216 int base; BDIGIT hbase; int hbase_numdigits; + BDIGIT_DBL hbase2; + int hbase2_numdigits; }; static size_t @@ -4223,27 +4225,24 @@ big2str_orig(struct big2str_struct *b2s, https://github.com/ruby/ruby/blob/trunk/bignum.c#L4225 { long i = RBIGNUM_LEN(x); size_t j = len; + int k; BDIGIT* ds = BDIGITS(x); + BDIGIT_DBL num; assert(i <= 2); - while (i && j > 0) { - long k = i; - BDIGIT_DBL num = 0; - - while (k--) { /* x / hbase */ - num = BIGUP(num) + ds[k]; - ds[k] = (BDIGIT)(num / b2s->hbase); - num %= b2s->hbase; - } - if (trim && ds[i-1] == 0) i--; - k = b2s->hbase_numdigits; - while (k--) { - ptr[--j] = ruby_digitmap[num % b2s->base]; - num /= b2s->base; - if (j <= 0) break; - if (trim && i == 0 && num == 0) break; - } + num = 0; + if (0 < i) + num = ds[0]; + if (1 < i) + num |= BIGUP(ds[1]); + + k = b2s->hbase2_numdigits; + while (k--) { + ptr[--j] = ruby_digitmap[num % b2s->base]; + num /= b2s->base; + if (j <= 0) break; + if (trim && num == 0) break; } if (trim) { while (j < len && ptr[j] == '0') j++; @@ -4372,6 +4371,7 @@ rb_big2str1(VALUE x, int base, int trim) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4371 b2s_data.base = base; b2s_data.hbase = maxpow_in_bdigit(base, &b2s_data.hbase_numdigits); + b2s_data.hbase2 = maxpow_in_bdigit_dbl(base, &b2s_data.hbase2_numdigits); off = !(trim && RBIGNUM_SIGN(x)); /* erase plus sign if trim */ xx = rb_big_clone(x); RBIGNUM_SET_SIGN(xx, 1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/