From 3c199bb70045e383258c10b3213899abd9630c81 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 10 Jan 2017 12:18:21 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index ee8c032eef..5f67214cba 100644 --- a/numeric.c +++ b/numeric.c @@ -3569,6 +3569,10 @@ fix_mul(VALUE x, VALUE y) 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)) { -- cgit v1.2.3