summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-31 21:33:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-31 21:33:14 +0000
commit39a00c67107a3ae41a49b8897fdaa51cbaede7fb (patch)
tree325bb427ab8d664589fdb0efaec87c959fcbe8c4
parent835c555f7f137746eb6f7cd32bd05a386852fdbe (diff)
* bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now.
(big2str_struct): Two fields added: hbase2, hbase2_numdigits. (rb_big2str1): Initialize above fields. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--bignum.c34
2 files changed, 23 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index f5118c7..a690f9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Aug 1 06:28:48 2013 Tanaka Akira <akr@fsij.org>
+
+ * 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@ruby-lang.org>
* lib/rdoc/options.rb (RDoc#finish): include root path in include
diff --git a/bignum.c b/bignum.c
index 5e6c337..738a490 100644
--- a/bignum.c
+++ b/bignum.c
@@ -4216,6 +4216,8 @@ struct big2str_struct {
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, VALUE x, char* ptr, size_t len, int tri
{
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)
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);