ruby-changes:4237
From: ko1@a...
Date: Fri, 7 Mar 2008 21:14:37 +0900 (JST)
Subject: [ruby-changes:4237] mame - Ruby:r15727 (trunk): * bignum.c (power_cache_init, power_cache_get_power0, Init_Bignum):
mame 2008-03-07 21:14:17 +0900 (Fri, 07 Mar 2008) New Revision: 15727 Modified files: trunk/ChangeLog trunk/bignum.c Log: * bignum.c (power_cache_init, power_cache_get_power0, Init_Bignum): delayed initializing power cache per base. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15727&r2=15726&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bignum.c?r1=15727&r2=15726&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 15726) +++ ChangeLog (revision 15727) @@ -1,3 +1,8 @@ +Fri Mar 7 21:12:19 2008 Yusuke Endoh <mame@t...> + + * bignum.c (power_cache_init, power_cache_get_power0, Init_Bignum): + delayed initializing power cache per base. + Fri Mar 7 20:30:05 2008 Nobuyoshi Nakada <nobu@r...> * cont.c (cont_restore_0): fixed typo. [ruby-core:15821] Index: bignum.c =================================================================== --- bignum.c (revision 15726) +++ bignum.c (revision 15727) @@ -737,17 +737,13 @@ #define MAX_BIG2STR_TABLE_ENTRIES 64 static VALUE big2str_power_cache[35][MAX_BIG2STR_TABLE_ENTRIES]; -static int power_cache_initialized = 0; static void power_cache_init(void) { int i, j; for (i = 0; i < 35; ++i) { - big2str_power_cache[i][0] = - rb_big_pow(rb_int2big(i+2), INT2FIX(KARATSUBA_DIGITS)); - rb_global_variable(&big2str_power_cache[i][0]); - for (j = 1; j < MAX_BIG2STR_TABLE_ENTRIES; ++j) { + for (j = 0; j < MAX_BIG2STR_TABLE_ENTRIES; ++j) { big2str_power_cache[i][j] = Qnil; } } @@ -758,7 +754,8 @@ { if (NIL_P(big2str_power_cache[base - 2][i])) { big2str_power_cache[base - 2][i] = - bigsqr(power_cache_get_power0(base, i - 1)); + i == 0 ? rb_big_pow(rb_int2big(base), INT2FIX(KARATSUBA_DIGITS)) + : bigsqr(power_cache_get_power0(base, i - 1)); rb_global_variable(&big2str_power_cache[base - 2][i]); } return big2str_power_cache[base - 2][i]; @@ -905,10 +902,6 @@ return big2str_orig(x, base, ptr, len, hbase, trim); } - if (!power_cache_initialized) { - power_cache_init(); - power_cache_initialized = 1; - } b = power_cache_get_power(base, n1, &m1); bigdivmod(x, b, &q, &r); lh = big2str_karatsuba(q, base, ptr, (len - m1)/2, @@ -2616,4 +2609,6 @@ rb_define_method(rb_cBignum, "size", rb_big_size, 0); rb_define_method(rb_cBignum, "odd?", rb_big_odd_p, 0); rb_define_method(rb_cBignum, "even?", rb_big_even_p, 0); + + power_cache_init(); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/