[前][次][番号順一覧][スレッド一覧]

ruby-changes:30312

From: akr <ko1@a...>
Date: Sun, 4 Aug 2013 01:02:42 +0900 (JST)
Subject: [ruby-changes:30312] akr:r42364 (trunk): * bignum.c (big2str_karatsuba): Don't allocate new temporary buffer

akr	2013-08-04 01:01:14 +0900 (Sun, 04 Aug 2013)

  New Revision: 42364

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42364

  Log:
    * bignum.c (big2str_karatsuba): Don't allocate new temporary buffer
      if the buffer is enough for current invocation.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42363)
+++ ChangeLog	(revision 42364)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Aug  4 00:57:58 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (big2str_karatsuba): Don't allocate new temporary buffer
+	  if the buffer is enough for current invocation.
+
 Sun Aug  4 00:22:34 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (bary2bdigitdbl): New function.
Index: bignum.c
===================================================================
--- bignum.c	(revision 42363)
+++ bignum.c	(revision 42364)
@@ -4383,12 +4383,13 @@ big2str_karatsuba(struct big2str_struct https://github.com/ruby/ruby/blob/trunk/bignum.c#L4383
             memset(b2s->ptr, '0', len);
             b2s->ptr += len;
         }
-        if (wn < bn * 4 + BIGDIVREM_EXTRA_WORDS) {
+        rn = bn;
+        qn = xn+BIGDIVREM_EXTRA_WORDS;
+        if (wn < rn + qn) {
             wn = bn * 4 + BIGDIVREM_EXTRA_WORDS;
+            assert(rn + qn <= wn);
             wds = ALLOCV_N(BDIGIT, tmpw, wn);
         }
-        rn = bn;
-        qn = xn+BIGDIVREM_EXTRA_WORDS;
         rds = wds;
         qds = wds+rn;
         bary_divmod(qds, qn, rds, rn, xds, xn, bds, bn);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]