diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-15 11:42:23 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-15 11:42:23 +0000 |
commit | 43e20c6a9afca385601e694b4ae55dbc05e87509 (patch) | |
tree | b062e1f20f18233f7a0d38dd23e85c75ef3c45f4 /enum.c | |
parent | 95d2ec93bc5d032dc6695d32d37f963a9617eeaf (diff) | |
download | ruby-43e20c6a9afca385601e694b4ae55dbc05e87509.tar.gz |
* 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.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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)); } |