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:
parent
14b3dc1ec4
commit
a3fb17f3a0
1 changed files with 3 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue