diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-30 05:36:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-30 05:36:59 +0000 |
commit | 56ce54608ca53c02c125e609d1e9eeea6025c4d9 (patch) | |
tree | f9bdd55efbfe727ea2b6f836fd3760b4b8e6e44b /array.c | |
parent | 4b9aeef1fa2f32a4555f88c6e83539374a1bd8d1 (diff) |
array.c: integer calculations
* array.c (rb_ary_cycle_size, descending_factorial): use
rb_int_mul instead of rb_funcallv.
* array.c (binomial_coefficient): use rb_int_idiv instead of
rb_funcallv.
* array.c (rb_ary_repeated_permutation_size): use
rb_int_positive_pow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -25,8 +25,6 @@ VALUE rb_cArray; -static ID id_div; - /* for OPTIMIZED_CMP: */ #define id_cmp idCmp @@ -4955,7 +4953,7 @@ rb_ary_cycle_size(VALUE self, VALUE args, VALUE eobj) mul = NUM2LONG(n); if (mul <= 0) return INT2FIX(0); n = LONG2FIX(mul); - return rb_funcallv(rb_ary_length(self), '*', 1, &n); + return rb_fix_mul_fix(rb_ary_length(self), n); } /* @@ -5084,7 +5082,7 @@ descending_factorial(long from, long how_many) VALUE cnt = LONG2FIX(how_many >= 0); while (how_many-- > 0) { VALUE v = LONG2FIX(from--); - cnt = rb_funcallv(cnt, '*', 1, &v); + cnt = rb_int_mul(cnt, v); } return cnt; } @@ -5101,7 +5099,7 @@ binomial_coefficient(long comb, long size) } r = descending_factorial(size, comb); v = descending_factorial(comb, comb); - return rb_funcallv(r, id_div, 1, &v); + return rb_int_idiv(r, v); } static VALUE @@ -5306,14 +5304,14 @@ rb_ary_repeated_permutation_size(VALUE ary, VALUE args, VALUE eobj) { long n = RARRAY_LEN(ary); long k = NUM2LONG(RARRAY_AREF(args, 0)); - VALUE v; if (k < 0) { return LONG2FIX(0); } - - v = LONG2NUM(k); - return rb_funcallv(LONG2NUM(n), idPow, 1, &v); + if (n <= 0) { + return LONG2FIX(!k); + } + return rb_int_positive_pow(n, (unsigned long)k); } /* @@ -6263,5 +6261,4 @@ Init_Array(void) rb_define_method(rb_cArray, "sum", rb_ary_sum, -1); id_random = rb_intern("random"); - id_div = rb_intern("div"); } |