1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

rational.c: short circuit optimization

* rational.c (nurat_reduce): short circuit when arguments are ONE,
  nothing is needed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-01-10 13:41:18 +00:00
parent 14b3dc1ec4
commit a3fb17f3a0

View file

@ -488,7 +488,9 @@ nurat_canonicalize(VALUE *num, VALUE *den)
static void
nurat_reduce(VALUE *x, VALUE *y)
{
VALUE gcd = f_gcd(*x, *y);
VALUE gcd;
if (*x == ONE || *y == ONE) return;
gcd = f_gcd(*x, *y);
*x = f_idiv(*x, gcd);
*y = f_idiv(*y, gcd);
}