1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* bignum.c (power_cache_init, power_cache_get_power0, Init_Bignum):

delayed initializing power cache per base.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-03-07 12:14:17 +00:00
parent 2bbf4707f7
commit a6267179ee
2 changed files with 10 additions and 10 deletions

View file

@ -1,3 +1,8 @@
Fri Mar 7 21:12:19 2008 Yusuke Endoh <mame@tsg.ne.jp>
* 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@ruby-lang.org>
* cont.c (cont_restore_0): fixed typo. [ruby-core:15821]

View file

@ -737,17 +737,13 @@ ceil_log2(register unsigned long x)
#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 @@ power_cache_get_power0(int base, int i)
{
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 @@ big2str_karatsuba(VALUE x, int base, char* ptr,
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 @@ Init_Bignum(void)
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();
}