summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-05 23:25:13 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-05 23:25:13 +0000
commit7a04666b3cb95c2b778b21d5dc2df70adad0c6c8 (patch)
treea2d1d7a42920f5d4b818081843f7c07757b5a85d /bignum.c
parentc8573378f6a099ad453b5c1f4a9ba3a691b1f9c1 (diff)
* bignum.c (bigdivrem1): optimization by skipping zeros at the
tail of digits. a patch from TOYOFUKU Chikanobu <nobu_toyofuku at nifty.com> in [ruby-dev:36169]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/bignum.c b/bignum.c
index 6ebbfa0b70..08e7ebb215 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1633,19 +1633,20 @@ bigdivrem1(void *ptr)
{
struct big_div_struct *bds = (struct big_div_struct*)ptr;
long nx = bds->nx, ny = bds->ny;
- long i, j;
+ long i, j, nyzero;
BDIGIT *yds = bds->yds, *zds = bds->zds;
BDIGIT_DBL t2;
BDIGIT_DBL_SIGNED num;
BDIGIT q;
j = nx==ny?nx+1:nx;
+ for (nyzero = 0; !yds[nyzero]; nyzero++);
do {
if (bds->stop) return Qnil;
if (zds[j] == yds[ny-1]) q = BIGRAD-1;
else q = (BDIGIT)((BIGUP(zds[j]) + zds[j-1])/yds[ny-1]);
if (q) {
- i = 0; num = 0; t2 = 0;
+ i = nyzero; num = 0; t2 = 0;
do { /* multiply and subtract */
BDIGIT_DBL ee;
t2 += (BDIGIT_DBL)yds[i] * q;