aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c11
1 files changed, 11 insertions, 0 deletions
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));
}