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

ruby-changes:30157

From: akr <ko1@a...>
Date: Sun, 28 Jul 2013 12:12:46 +0900 (JST)
Subject: [ruby-changes:30157] akr:r42209 (trunk): * bignum.c: Constify bary_* functions.

akr	2013-07-28 12:12:36 +0900 (Sun, 28 Jul 2013)

  New Revision: 42209

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

  Log:
    * bignum.c: Constify bary_* functions.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42208)
+++ ChangeLog	(revision 42209)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jul 28 12:03:23 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c: Constify bary_* functions.
+
 Sun Jul 28 11:12:07 2013  Tanaka Akira  <akr@f...>
 
 	* include/ruby/intern.h (rb_absint_size): Declaration moved from
Index: bignum.c
===================================================================
--- bignum.c	(revision 42208)
+++ bignum.c	(revision 42209)
@@ -127,15 +127,15 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdi https://github.com/ruby/ruby/blob/trunk/bignum.c#L127
 #define KARATSUBA_MUL_DIGITS 70
 #define TOOM3_MUL_DIGITS 150
 
-typedef void (mulfunc_t)(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl);
+typedef void (mulfunc_t)(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl);
 
 static mulfunc_t bary_mul_toom3_start;
 static mulfunc_t bary_mul_karatsuba_start;
-static BDIGIT bigdivrem_single(BDIGIT *qds, BDIGIT *xds, long nx, BDIGIT y);
-static void bary_divmod(BDIGIT *qds, size_t nq, BDIGIT *rds, size_t nr, BDIGIT *xds, size_t nx, BDIGIT *yds, size_t ny);
+static BDIGIT bigdivrem_single(BDIGIT *qds, const BDIGIT *xds, long nx, BDIGIT y);
+static void bary_divmod(BDIGIT *qds, size_t nq, BDIGIT *rds, size_t nr, const BDIGIT *xds, size_t nx, const BDIGIT *yds, size_t ny);
 
 static VALUE bigmul0(VALUE x, VALUE y);
-static void bary_mul_toom3(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn);
+static void bary_mul_toom3(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn);
 static VALUE bignew_1(VALUE klass, long len, int sign);
 static inline VALUE bigtrunc(VALUE x);
 
@@ -482,7 +482,7 @@ maxpow_in_bdigit(int base, int *exp_ret) https://github.com/ruby/ruby/blob/trunk/bignum.c#L482
 }
 
 static BDIGIT
-bary_small_lshift(BDIGIT *zds, BDIGIT *xds, size_t n, int shift)
+bary_small_lshift(BDIGIT *zds, const BDIGIT *xds, size_t n, int shift)
 {
     size_t i;
     BDIGIT_DBL num = 0;
@@ -497,7 +497,7 @@ bary_small_lshift(BDIGIT *zds, BDIGIT *x https://github.com/ruby/ruby/blob/trunk/bignum.c#L497
 }
 
 static void
-bary_small_rshift(BDIGIT *zds, BDIGIT *xds, size_t n, int shift, int sign_bit)
+bary_small_rshift(BDIGIT *zds, const BDIGIT *xds, size_t n, int shift, int sign_bit)
 {
     BDIGIT_DBL num = 0;
     BDIGIT x;
@@ -1396,7 +1396,7 @@ bary_unpack(BDIGIT *bdigits, size_t num_ https://github.com/ruby/ruby/blob/trunk/bignum.c#L1396
 }
 
 static int
-bary_subb(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn, int borrow)
+bary_subb(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, int borrow)
 {
     BDIGIT_DBL_SIGNED num;
     size_t i;
@@ -1447,7 +1447,7 @@ bary_subb(BDIGIT *zds, size_t zn, BDIGIT https://github.com/ruby/ruby/blob/trunk/bignum.c#L1447
 }
 
 static int
-bary_sub(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn)
+bary_sub(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 {
     return bary_subb(zds, zn, xds, xn, yds, yn, 0);
 }
@@ -1459,7 +1459,7 @@ bary_sub_one(BDIGIT *zds, size_t zn) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1459
 }
 
 static int
-bary_addc(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn, int carry)
+bary_addc(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, int carry)
 {
     BDIGIT_DBL num;
     size_t i;
@@ -1468,7 +1468,7 @@ bary_addc(BDIGIT *zds, size_t zn, BDIGIT https://github.com/ruby/ruby/blob/trunk/bignum.c#L1468
     assert(yn <= zn);
 
     if (xn > yn) {
-	BDIGIT *tds;
+	const BDIGIT *tds;
 	tds = xds; xds = yds; yds = tds;
 	i = xn; xn = yn; yn = i;
     }
@@ -1505,7 +1505,7 @@ bary_addc(BDIGIT *zds, size_t zn, BDIGIT https://github.com/ruby/ruby/blob/trunk/bignum.c#L1505
 }
 
 static int
-bary_add(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn)
+bary_add(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
 {
     return bary_addc(zds, zn, xds, xn, yds, yn, 0);
 }
@@ -1537,7 +1537,7 @@ bary_mul_single(BDIGIT *zds, size_t zl, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1537
 }
 
 static int
-bary_muladd_1xN(BDIGIT *zds, size_t zl, BDIGIT x, BDIGIT *yds, size_t yl)
+bary_muladd_1xN(BDIGIT *zds, size_t zl, BDIGIT x, const BDIGIT *yds, size_t yl)
 {
     BDIGIT_DBL n;
     BDIGIT_DBL dd;
@@ -1572,7 +1572,7 @@ bary_muladd_1xN(BDIGIT *zds, size_t zl, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1572
 }
 
 static BDIGIT_DBL_SIGNED
-bigdivrem_mulsub(BDIGIT *zds, size_t zn, BDIGIT x, BDIGIT *yds, size_t yn)
+bigdivrem_mulsub(BDIGIT *zds, size_t zn, BDIGIT x, const BDIGIT *yds, size_t yn)
 {
     size_t i;
     BDIGIT_DBL t2;
@@ -1598,7 +1598,7 @@ bigdivrem_mulsub(BDIGIT *zds, size_t zn, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1598
 }
 
 static int
-bary_mulsub_1xN(BDIGIT *zds, size_t zn, BDIGIT x, BDIGIT *yds, size_t yn)
+bary_mulsub_1xN(BDIGIT *zds, size_t zn, BDIGIT x, const BDIGIT *yds, size_t yn)
 {
     BDIGIT_DBL_SIGNED num;
 
@@ -1612,7 +1612,7 @@ bary_mulsub_1xN(BDIGIT *zds, size_t zn, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1612
 }
 
 static void
-bary_mul_normal(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl)
+bary_mul_normal(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl)
 {
     size_t i;
 
@@ -1640,7 +1640,7 @@ rb_big_mul_normal(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1640
  *      http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf
  */
 static void
-bary_sq_fast(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn)
+bary_sq_fast(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn)
 {
     size_t i, j;
     BDIGIT_DBL c, v, w;
@@ -1705,7 +1705,7 @@ rb_big_sq_fast(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1705
 
 /* balancing multiplication by slicing larger argument */
 static void
-bary_mul_balance_with_mulfunc(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl, mulfunc_t *mulfunc)
+bary_mul_balance_with_mulfunc(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl, mulfunc_t *mulfunc)
 {
     VALUE work = 0;
     size_t yl0 = yl;
@@ -1765,7 +1765,7 @@ rb_big_mul_balance(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1765
 
 /* multiplication by karatsuba method */
 static void
-bary_mul_karatsuba(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
+bary_mul_karatsuba(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
 {
     VALUE work = 0;
 
@@ -1776,7 +1776,8 @@ bary_mul_karatsuba(BDIGIT *zds, size_t z https://github.com/ruby/ruby/blob/trunk/bignum.c#L1776
     int odd_xy = 0;
     int sq;
 
-    BDIGIT *xds0, *xds1, *yds0, *yds1, *zds0, *zds1, *zds2, *zds3;
+    const BDIGIT *xds0, *xds1, *yds0, *yds1;
+    BDIGIT *zds0, *zds1, *zds2, *zds3;
 
     assert(xl + yl <= zl);
     assert(xl <= yl);
@@ -1946,19 +1947,19 @@ rb_big_mul_karatsuba(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1947
 }
 
 static void
-bary_mul_toom3(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
+bary_mul_toom3(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn)
 {
     size_t n;
     size_t wnc;
     VALUE work = 0;
 
     /* "p" means "positive".  Actually "non-negative", though. */
-    size_t x0n; BDIGIT *x0ds;
-    size_t x1n; BDIGIT *x1ds;
-    size_t x2n; BDIGIT *x2ds;
-    size_t y0n; BDIGIT *y0ds;
-    size_t y1n; BDIGIT *y1ds;
-    size_t y2n; BDIGIT *y2ds;
+    size_t x0n; const BDIGIT *x0ds;
+    size_t x1n; const BDIGIT *x1ds;
+    size_t x2n; const BDIGIT *x2ds;
+    size_t y0n; const BDIGIT *y0ds;
+    size_t y1n; const BDIGIT *y1ds;
+    size_t y2n; const BDIGIT *y2ds;
 
     size_t u1n; BDIGIT *u1ds; int u1p;
     size_t u2n; BDIGIT *u2ds; int u2p;
@@ -2346,7 +2347,7 @@ rb_big_mul_toom3(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2347
 }
 
 static void
-bary_mul1(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl)
+bary_mul1(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl)
 {
     assert(xl + yl <= zl);
 
@@ -2361,7 +2362,7 @@ bary_mul1(BDIGIT *zds, size_t zl, BDIGIT https://github.com/ruby/ruby/blob/trunk/bignum.c#L2362
 
 /* determine whether a bignum is sparse or not by random sampling */
 static inline int
-bary_sparse_p(BDIGIT *ds, size_t n)
+bary_sparse_p(const BDIGIT *ds, size_t n)
 {
     long c = 0;
 
@@ -2373,15 +2374,15 @@ bary_sparse_p(BDIGIT *ds, size_t n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2374
 }
 
 static int
-bary_mul_precheck(BDIGIT **zdsp, size_t *zlp, BDIGIT **xdsp, size_t *xlp, BDIGIT **ydsp, size_t *ylp)
+bary_mul_precheck(BDIGIT **zdsp, size_t *zlp, const BDIGIT **xdsp, size_t *xlp, const BDIGIT **ydsp, size_t *ylp)
 {
     size_t nlsz; /* number of least significant zero BDIGITs */
 
     BDIGIT *zds = *zdsp;
     size_t zl = *zlp;
-    BDIGIT *xds = *xdsp;
+    const BDIGIT *xds = *xdsp;
     size_t xl = *xlp;
-    BDIGIT *yds = *ydsp;
+    const BDIGIT *yds = *ydsp;
     size_t yl = *ylp;
 
     assert(xl + yl <= zl);
@@ -2428,7 +2429,7 @@ bary_mul_precheck(BDIGIT **zdsp, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L2429
 
     /* make sure that y is longer than x */
     if (xl > yl) {
-        BDIGIT *tds;
+        const BDIGIT *tds;
         size_t tl;
 	tds = xds; xds = yds; yds = tds;
 	tl = xl; xl = yl; yl = tl;
@@ -2471,7 +2472,7 @@ bary_mul_precheck(BDIGIT **zdsp, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L2472
 }
 
 static void
-bary_mul_karatsuba_branch(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
+bary_mul_karatsuba_branch(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
 {
     /* normal multiplication when x is small */
     if (xl < KARATSUBA_MUL_DIGITS) {
@@ -2501,7 +2502,7 @@ bary_mul_karatsuba_branch(BDIGIT *zds, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L2502
 }
 
 static void
-bary_mul_karatsuba_start(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
+bary_mul_karatsuba_start(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
 {
     if (bary_mul_precheck(&zds, &zl, &xds, &xl, &yds, &yl))
         return;
@@ -2510,7 +2511,7 @@ bary_mul_karatsuba_start(BDIGIT *zds, si https://github.com/ruby/ruby/blob/trunk/bignum.c#L2511
 }
 
 static void
-bary_mul_toom3_branch(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
+bary_mul_toom3_branch(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
 {
     if (yl < TOOM3_MUL_DIGITS) {
         bary_mul_karatsuba_branch(zds, zl, xds, xl, yds, yl, wds, wl);
@@ -2526,7 +2527,7 @@ bary_mul_toom3_branch(BDIGIT *zds, size_ https://github.com/ruby/ruby/blob/trunk/bignum.c#L2527
 }
 
 static void
-bary_mul_toom3_start(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
+bary_mul_toom3_start(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl, BDIGIT *wds, size_t wl)
 {
     if (bary_mul_precheck(&zds, &zl, &xds, &xl, &yds, &yl))
         return;
@@ -2535,7 +2536,7 @@ bary_mul_toom3_start(BDIGIT *zds, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L2536
 }
 
 static void
-bary_mul(BDIGIT *zds, size_t zl, BDIGIT *xds, size_t xl, BDIGIT *yds, size_t yl)
+bary_mul(BDIGIT *zds, size_t zl, const BDIGIT *xds, size_t xl, const BDIGIT *yds, size_t yl)
 {
     if (xl < KARATSUBA_MUL_DIGITS || yl < KARATSUBA_MUL_DIGITS) {
         if (xds == yds && xl == yl)
@@ -2606,7 +2607,7 @@ bigdivrem_num_extra_words(long nx, long https://github.com/ruby/ruby/blob/trunk/bignum.c#L2607
 }
 
 static BDIGIT
-bigdivrem_single(BDIGIT *qds, BDIGIT *xds, long nx, BDIGIT y)
+bigdivrem_single(BDIGIT *qds, const BDIGIT *xds, long nx, BDIGIT y)
 {
     long i;
     BDIGIT_DBL t2;
@@ -2621,7 +2622,7 @@ bigdivrem_single(BDIGIT *qds, BDIGIT *xd https://github.com/ruby/ruby/blob/trunk/bignum.c#L2622
 }
 
 static void
-bigdivrem_normal(BDIGIT *zds, long nz, BDIGIT *xds, long nx, BDIGIT *yds, long ny, int needs_mod)
+bigdivrem_normal(BDIGIT *zds, long nz, const BDIGIT *xds, long nx, BDIGIT *yds, long ny, int needs_mod)
 {
     struct big_div_struct bds;
     BDIGIT q;
@@ -2666,7 +2667,7 @@ bigdivrem_normal(BDIGIT *zds, long nz, B https://github.com/ruby/ruby/blob/trunk/bignum.c#L2667
 }
 
 static void
-bary_divmod(BDIGIT *qds, size_t nq, BDIGIT *rds, size_t nr, BDIGIT *xds, size_t nx, BDIGIT *yds, size_t ny)
+bary_divmod(BDIGIT *qds, size_t nq, BDIGIT *rds, size_t nr, const BDIGIT *xds, size_t nx, const BDIGIT *yds, size_t ny)
 {
     assert(nx <= nq);
     assert(ny <= nr);
@@ -2725,7 +2726,7 @@ bary_divmod(BDIGIT *qds, size_t nq, BDIG https://github.com/ruby/ruby/blob/trunk/bignum.c#L2726
         if (BDIGIT_MSB(yds[ny-1])) {
             /* bigdivrem_normal will not modify y.
              * So use yds directly.  */
-            tds = yds;
+            tds = (BDIGIT *)yds;
         }
         else {
             /* bigdivrem_normal will modify y.

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

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