aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--enum.c11
2 files changed, 16 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d1618d1f3..f68fc81a4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Mar 15 20:32:57 2016 Tanaka Akira <akr@fsij.org>
+
+ * enum.c (enum_inject): Implement the specialied code for :+ operator
+ for Fixnums.
+
Tue Mar 15 20:21:01 2016 Tanaka Akira <akr@fsij.org>
* enum.c (enum_inject): Implement the specialized code for self is an
diff --git a/enum.c b/enum.c
index 49cd8ef7af..ba444e33c6 100644
--- a/enum.c
+++ b/enum.c
@@ -719,6 +719,17 @@ enum_inject(int argc, VALUE *argv, VALUE obj)
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));
}