diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-18 03:42:35 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-18 03:42:35 +0000 |
commit | 7dccda437bf7a83f43f0c2b5fe22de5ca5058347 (patch) | |
tree | 10ed7458b2e65ca689c47f4e78df52b08ca2e283 /array.c | |
parent | 3d031cea420f9dcfbd6beda8908fe05e849210e8 (diff) |
array.c: finish_exact_sum
* array.c (finish_exact_sum): extract duplicate code from
rb_ary_sum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 41 |
1 files changed, 19 insertions, 22 deletions
@@ -5733,6 +5733,23 @@ rb_ary_dig(int argc, VALUE *argv, VALUE self) return rb_obj_dig(argc, argv, self, Qnil); } +static inline VALUE +finish_exact_sum(long n, VALUE r, VALUE v) +{ + if (n != 0) + v = rb_fix_plus(LONG2FIX(n), v); + if (r != Qundef) { + /* r can be an Integer when mathn is loaded */ + if (FIXNUM_P(r)) + v = rb_fix_plus(r, v); + else if (RB_TYPE_P(r, T_BIGNUM)) + v = rb_big_plus(r, v); + else + v = rb_rational_plus(r, v); + } + return v; +} + /* * call-seq: * ary.sum(init=0) -> number @@ -5814,31 +5831,11 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary) else goto not_exact; } - if (n != 0) - v = rb_fix_plus(LONG2FIX(n), v); - if (r != Qundef) { - /* r can be an Integer when mathn is loaded */ - if (FIXNUM_P(r)) - v = rb_fix_plus(r, v); - else if (RB_TYPE_P(r, T_BIGNUM)) - v = rb_big_plus(r, v); - else - v = rb_rational_plus(r, v); - } + v = finish_exact_sum(n, r, v); return v; not_exact: - if (n != 0) - v = rb_fix_plus(LONG2FIX(n), v); - if (r != Qundef) { - /* r can be an Integer when mathn is loaded */ - if (FIXNUM_P(r)) - v = rb_fix_plus(r, v); - else if (RB_TYPE_P(r, T_BIGNUM)) - v = rb_big_plus(r, v); - else - v = rb_rational_plus(r, v); - } + v = finish_exact_sum(n, r, v); if (RB_FLOAT_TYPE_P(e)) { /* |