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

ruby-changes:44634

From: mrkn <ko1@a...>
Date: Fri, 11 Nov 2016 23:42:57 +0900 (JST)
Subject: [ruby-changes:44634] mrkn:r56709 (trunk): rational.c: optimize rational + rational

mrkn	2016-11-11 23:42:53 +0900 (Fri, 11 Nov 2016)

  New Revision: 56709

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

  Log:
    rational.c: optimize rational + rational
    
    * rational.c (f_addsub): optimize rational + rational.
      Author: Tadashi Saito <tad.a.digger@g...>

  Modified files:
    trunk/rational.c
Index: rational.c
===================================================================
--- rational.c	(revision 56708)
+++ rational.c	(revision 56709)
@@ -691,32 +691,32 @@ f_addsub(VALUE self, VALUE anum, VALUE a https://github.com/ruby/ruby/blob/trunk/rational.c#L691
 	VALUE c;
 
 	if (k == '+')
-	    c = f_add(a, b);
+	    c = rb_int_plus(a, b);
 	else
 	    c = f_sub(a, b);
 
-	b = f_idiv(aden, g);
+	b = rb_int_idiv(aden, g);
 	g = f_gcd(c, g);
-	num = f_idiv(c, g);
-	a = f_idiv(bden, g);
-	den = f_mul(a, b);
+	num = rb_int_idiv(c, g);
+	a = rb_int_idiv(bden, g);
+	den = rb_int_mul(a, b);
     }
     else {
 	VALUE g = f_gcd(aden, bden);
-	VALUE a = f_mul(anum, f_idiv(bden, g));
-	VALUE b = f_mul(bnum, f_idiv(aden, g));
+	VALUE a = rb_int_mul(anum, rb_int_idiv(bden, g));
+	VALUE b = rb_int_mul(bnum, rb_int_idiv(aden, g));
 	VALUE c;
 
 	if (k == '+')
-	    c = f_add(a, b);
+	    c = rb_int_plus(a, b);
 	else
 	    c = f_sub(a, b);
 
-	b = f_idiv(aden, g);
+	b = rb_int_idiv(aden, g);
 	g = f_gcd(c, g);
-	num = f_idiv(c, g);
-	a = f_idiv(bden, g);
-	den = f_mul(a, b);
+	num = rb_int_idiv(c, g);
+	a = rb_int_idiv(bden, g);
+	den = rb_int_mul(a, b);
     }
     return f_rational_new_no_reduce2(CLASS_OF(self), num, den);
 }

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

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