summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-15 11:42:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-15 11:42:23 +0000
commit43e20c6a9afca385601e694b4ae55dbc05e87509 (patch)
treeb062e1f20f18233f7a0d38dd23e85c75ef3c45f4 /enum.c
parent95d2ec93bc5d032dc6695d32d37f963a9617eeaf (diff)
* enum.c (enum_inject): Implement the specialied code for :+ operator
for Fixnums. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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));
}