aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-10 13:41:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-10 13:41:18 +0000
commit351cc2d7c9b942a34e19ef6e832a5358a99b32e4 (patch)
tree94fc73fc466cab366907424dfe5883c2470e55ea /rational.c
parent87c1b19c899815414e4102c400424be6a00308ad (diff)
downloadruby-351cc2d7c9b942a34e19ef6e832a5358a99b32e4.tar.gz
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
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/rational.c b/rational.c
index 212ad07faa..26324899e5 100644
--- a/rational.c
+++ b/rational.c
@@ -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);
}