diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-13 01:21:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-13 01:21:59 +0000 |
commit | 8ee960c55c1854b4900bf8ad8b689ccb1a265543 (patch) | |
tree | 4266bda51672fa18ccb6f81611eb98c232ae1c51 /bignum.c | |
parent | c3b656bc8eb8fede8de7c2505e1135f8d7c399f0 (diff) |
bignum.c: call functions directly
* bignum.c (int_pow_tmp{1,2,3}): call dedicated functions directly
for internal calculations, instead of method calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 35 |
1 files changed, 18 insertions, 17 deletions
@@ -6938,7 +6938,7 @@ int_pow_tmp3(VALUE x, VALUE y, VALUE m, int nega_flg) z = bignew(zn, 1); bary_powm_gmp(BDIGITS(z), zn, BDIGITS(x), xn, BDIGITS(y), yn, BDIGITS(m), mn); if (nega_flg & BIGNUM_POSITIVE_P(z)) { - z = rb_funcall(z, '-', 1, m); + z = rb_big_minus(z, m); } RB_GC_GUARD(x); RB_GC_GUARD(y); @@ -6948,25 +6948,25 @@ int_pow_tmp3(VALUE x, VALUE y, VALUE m, int nega_flg) VALUE tmp = LONG2FIX(1L); long yy; - for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, rb_intern(">>"), 1, LONG2FIX(1L))) { - if (RTEST(rb_funcall(y, rb_intern("odd?"), 0))) { - tmp = rb_funcall(tmp, '*', 1, x); + for (/*NOP*/; ! FIXNUM_P(y); y = rb_big_rshift(y, LONG2FIX(1L))) { + if (RTEST(rb_int_odd_p(y))) { + tmp = rb_int_mul(tmp, x); tmp = rb_int_modulo(tmp, m); } - x = rb_funcall(x, '*', 1, x); + x = rb_int_mul(x, x); x = rb_int_modulo(x, m); } for (yy = FIX2LONG(y); yy; yy >>= 1L) { if (yy & 1L) { - tmp = rb_funcall(tmp, '*', 1, x); + tmp = rb_int_mul(tmp, x); tmp = rb_int_modulo(tmp, m); } - x = rb_funcall(x, '*', 1, x); + x = rb_int_mul(x, x); x = rb_int_modulo(x, m); } - if (nega_flg && RTEST(rb_funcall(tmp, rb_intern("positive?"), 0))) { - tmp = rb_funcall(tmp, '-', 1, m); + if (nega_flg && rb_num_positive_int_p(tmp)) { + tmp = rb_int_minus(tmp, m); } return tmp; #endif @@ -6983,7 +6983,7 @@ int_pow_tmp1(VALUE x, VALUE y, long mm, int nega_flg) long tmp = 1L; long yy; - for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) { + for (/*NOP*/; ! FIXNUM_P(y); y = rb_big_rshift(y, LONG2FIX(1L))) { if (RTEST(rb_int_odd_p(y))) { tmp = (tmp * xx) % mm; } @@ -7019,7 +7019,7 @@ int_pow_tmp2(VALUE x, VALUE y, long mm, int nega_flg) # define MUL_MODULO(a, b, c) rb_int_modulo(rb_fix_mul_fix((a), (b)), (c)) #endif - for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) { + for (/*NOP*/; ! FIXNUM_P(y); y = rb_big_rshift(y, LONG2FIX(1L))) { if (RTEST(rb_int_odd_p(y))) { tmp2 = MUL_MODULO(tmp2, xx, m); } @@ -7078,22 +7078,23 @@ rb_int_powm(int const argc, VALUE * const argv, VALUE const num) } if (rb_num_negative_int_p(m)) { - m = rb_funcall(m, idUMinus, 0); + m = rb_int_uminus(m); nega_flg = 1; } - if (!rb_num_positive_int_p(m)) { - rb_num_zerodiv(); - } if (FIXNUM_P(m)) { long const half_val = (long)HALF_LONG_MSB; long const mm = FIX2LONG(m); + if (!mm) rb_num_zerodiv(); if (mm <= half_val) { return int_pow_tmp1(rb_int_modulo(a, m), b, mm, nega_flg); - } else { + } + else { return int_pow_tmp2(rb_int_modulo(a, m), b, mm, nega_flg); } - } else if (RB_TYPE_P(m, T_BIGNUM)) { + } + else { + if (rb_bigzero_p(m)) rb_num_zerodiv(); return int_pow_tmp3(rb_int_modulo(a, m), b, m, nega_flg); } } |