diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-08 11:10:19 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-08 11:10:19 +0000 |
commit | 2ed666cbafff88bb736db034275e2689ceca30cd (patch) | |
tree | d9479df1d60221d380cf1997f1c2d344a769aa1b | |
parent | 6f0aeb60c43f5263b1618daf0a0f628ea64bbd80 (diff) | |
download | ruby-2ed666cbafff88bb736db034275e2689ceca30cd.tar.gz |
* bignum.c (power_cache_get_power0): no need to register address.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@19244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | bignum.c | 36 |
2 files changed, 19 insertions, 21 deletions
@@ -1,3 +1,7 @@ +Mon Sep 8 20:10:12 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * bignum.c (power_cache_get_power0): no need to register address. + Mon Sep 8 17:26:51 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * st.c (garbage_collect): checks if memory can be reclaimed. @@ -758,32 +758,24 @@ typedef VALUE (*big2str_power_cache_t)[MAX_BIG2STR_TABLE_ENTRIES]; static void power_cache_init(void) { - int i, j; VALUE cache_value = rb_ary_new2(35 * MAX_BIG2STR_TABLE_ENTRIES); - big2str_power_cache_t big2str_power_cache = - (big2str_power_cache_t)RARRAY_PTR(cache_value); - - for (i = 0; i < 35; ++i) { - for (j = 0; j < MAX_BIG2STR_TABLE_ENTRIES; ++j) { - big2str_power_cache[i][j] = Qnil; - } - } + rb_big2str_power_cache = cache_value; } static inline VALUE -power_cache_get_power0(int base, int i) +power_cache_get_power0(big2str_power_cache_t cache, int base, int i) { - VALUE cache_value = rb_big2str_power_cache; - big2str_power_cache_t big2str_power_cache = - (big2str_power_cache_t)RARRAY_PTR(cache_value); - - if (NIL_P(big2str_power_cache[base - 2][i])) { - big2str_power_cache[base - 2][i] = - 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]); + if (NIL_P(cache[base - 2][i])) { + if (i == 0) { + cache[base - 2][i] = + rb_big_pow(rb_int2big(base), INT2FIX(KARATSUBA_DIGITS)); + } + else { + cache[base - 2][i] = + bigsqr(power_cache_get_power0(cache, base, i - 1)); + } } - return big2str_power_cache[base - 2][i]; + return cache[base - 2][i]; } static VALUE @@ -791,6 +783,7 @@ power_cache_get_power(int base, long n1, long* m1) { long i, j, m; VALUE t; + big2str_power_cache_t cache; if (n1 <= KARATSUBA_DIGITS) rb_bug("n1 > KARATSUBA_DIGITS"); @@ -800,7 +793,8 @@ power_cache_get_power(int base, long n1, long* m1) i = m - LOG2_KARATSUBA_DIGITS; if (i >= MAX_BIG2STR_TABLE_ENTRIES) i = MAX_BIG2STR_TABLE_ENTRIES - 1; - t = power_cache_get_power0(base, i); + cache = (big2str_power_cache_t)RARRAY_PTR(rb_big2str_power_cache); + t = power_cache_get_power0(cache, base, i); j = KARATSUBA_DIGITS*(1 << i); while (n1 > j) { |