ruby-changes:44631
From: mrkn <ko1@a...>
Date: Fri, 11 Nov 2016 23:39:04 +0900 (JST)
Subject: [ruby-changes:44631] mrkn:r56704 (trunk): rational.c: optimize rational + float.
mrkn 2016-11-11 23:38:59 +0900 (Fri, 11 Nov 2016) New Revision: 56704 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56704 Log: rational.c: optimize rational + float. * rational.c (rb_rational_plus): optimize rational + float. Author: Tadashi Saito <tad.a.digger@g...> Modified files: trunk/rational.c Index: rational.c =================================================================== --- rational.c (revision 56703) +++ rational.c (revision 56704) @@ -715,6 +715,7 @@ f_addsub(VALUE self, VALUE anum, VALUE a https://github.com/ruby/ruby/blob/trunk/rational.c#L715 return f_rational_new_no_reduce2(CLASS_OF(self), num, den); } +static VALUE nurat_to_f(VALUE self); /* * call-seq: * rat + numeric -> numeric @@ -740,7 +741,7 @@ rb_rational_plus(VALUE self, VALUE other https://github.com/ruby/ruby/blob/trunk/rational.c#L741 } } else if (RB_TYPE_P(other, T_FLOAT)) { - return f_add(f_to_f(self), other); + return DBL2NUM(RFLOAT_VALUE(nurat_to_f(self)) + RFLOAT_VALUE(other)); } else if (RB_TYPE_P(other, T_RATIONAL)) { { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/