[前][次][番号順一覧][スレッド一覧]

ruby-changes:45576

From: nobu <ko1@a...>
Date: Sat, 18 Feb 2017 12:42:40 +0900 (JST)
Subject: [ruby-changes:45576] nobu:r57649 (trunk): array.c: finish_exact_sum

nobu	2017-02-18 12:42:35 +0900 (Sat, 18 Feb 2017)

  New Revision: 57649

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57649

  Log:
    array.c: finish_exact_sum
    
    * array.c (finish_exact_sum): extract duplicate code from
      rb_ary_sum.

  Modified files:
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 57648)
+++ array.c	(revision 57649)
@@ -5733,6 +5733,23 @@ rb_ary_dig(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/array.c#L5733
     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 https://github.com/ruby/ruby/blob/trunk/array.c#L5831
         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)) {
         /*

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]