From 43e20c6a9afca385601e694b4ae55dbc05e87509 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 15 Mar 2016 11:42:23 +0000 Subject: * 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 --- enum.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'enum.c') 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