[前][次][番号順一覧][スレッド一覧]

ruby-changes:45226

From: nobu <ko1@a...>
Date: Tue, 10 Jan 2017 22:41:23 +0900 (JST)
Subject: [ruby-changes:45226] nobu:r57299 (trunk): rational.c: short circuit optimization

nobu	2017-01-10 22:41:18 +0900 (Tue, 10 Jan 2017)

  New Revision: 57299

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57299

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

  Modified files:
    trunk/rational.c
Index: rational.c
===================================================================
--- rational.c	(revision 57298)
+++ rational.c	(revision 57299)
@@ -488,7 +488,9 @@ nurat_canonicalize(VALUE *num, VALUE *de https://github.com/ruby/ruby/blob/trunk/rational.c#L488
 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);
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]