ruby-changes:45223
From: nobu <ko1@a...>
Date: Tue, 10 Jan 2017 21:18:32 +0900 (JST)
Subject: [ruby-changes:45223] nobu:r57296 (trunk): numeric.c: short circuit optimization
nobu 2017-01-10 21:18:21 +0900 (Tue, 10 Jan 2017) New Revision: 57296 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57296 Log: numeric.c: short circuit optimization * numeric.c (fix_mul): short circuit when multiplication of Bignum and 0 or 1 not to make a Bignum unnecessarily. Modified files: trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 57295) +++ numeric.c (revision 57296) @@ -3569,6 +3569,10 @@ fix_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3569 return rb_fix_mul_fix(x, y); } else if (RB_TYPE_P(y, T_BIGNUM)) { + switch (x) { + case INT2FIX(0): return x; + case INT2FIX(1): return y; + } return rb_big_mul(y, x); } else if (RB_TYPE_P(y, T_FLOAT)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/