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

ruby-changes:42046

From: akr <ko1@a...>
Date: Tue, 15 Mar 2016 20:42:27 +0900 (JST)
Subject: [ruby-changes:42046] akr:r54120 (trunk): * enum.c (enum_inject): Implement the specialied code for :+ operator

akr	2016-03-15 20:42:23 +0900 (Tue, 15 Mar 2016)

  New Revision: 54120

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

  Log:
    * enum.c (enum_inject): Implement the specialied code for :+ operator
      for Fixnums.

  Modified files:
    trunk/ChangeLog
    trunk/enum.c
Index: enum.c
===================================================================
--- enum.c	(revision 54119)
+++ enum.c	(revision 54120)
@@ -719,6 +719,17 @@ enum_inject(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/enum.c#L719
             i = 0;
         }
         id = SYM2ID(op);
+        if (id == idPLUS && FIXNUM_P(v)) {
+            long n = FIX2LONG(v);
+            while (i < RARRAY_LEN(obj)) {
+                VALUE e = RARRAY_AREF(obj, i);
+                if (!FIXNUM_P(e)) break;
+                n += FIX2LONG(e); /* should not overflow long type */
+                i++;
+                if (!FIXABLE(n)) break;
+            }
+            v = LONG2NUM(n);
+        }
         for (; i<RARRAY_LEN(obj); i++) {
             v = rb_funcall(v, id, 1, RARRAY_AREF(obj, i));
         }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54119)
+++ ChangeLog	(revision 54120)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Mar 15 20:32:57 2016  Tanaka Akira  <akr@f...>
+
+	* enum.c (enum_inject): Implement the specialied code for :+ operator
+	  for Fixnums.
+
 Tue Mar 15 20:21:01 2016  Tanaka Akira  <akr@f...>
 
 	* enum.c (enum_inject): Implement the specialized code for self is an

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

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