Skip to content

Commit

Permalink
rational.c: short circuit optimization
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Jan 10, 2017
1 parent 14b3dc1 commit a3fb17f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rational.c
Expand Up @@ -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);
}
Expand Down

0 comments on commit a3fb17f

Please sign in to comment.