ruby-changes:44703
From: nobu <ko1@a...>
Date: Mon, 14 Nov 2016 13:06:21 +0900 (JST)
Subject: [ruby-changes:44703] nobu:r56776 (trunk): complex.c: optimize
nobu 2016-11-14 13:06:15 +0900 (Mon, 14 Nov 2016) New Revision: 56776 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56776 Log: complex.c: optimize * complex.c (f_negative_p): use rb_num_negative_p instead of funcall. * complex.c (f_kind_of_p, f_numeric_p): cast down to int because rb_obj_is_kind_of is safe. * complex.c (f_signbit, f_tpositive_p): remove f_boolcast. Modified files: trunk/complex.c Index: complex.c =================================================================== --- complex.c (revision 56775) +++ complex.c (revision 56776) @@ -177,12 +177,12 @@ fun2(expt) https://github.com/ruby/ruby/blob/trunk/complex.c#L177 fun2(fdiv) fun2(quo) -inline static VALUE +inline static int f_negative_p(VALUE x) { if (FIXNUM_P(x)) - return f_boolcast(FIXNUM_NEGATIVE_P(x)); - return rb_funcall(x, '<', 1, ZERO); + return FIXNUM_NEGATIVE_P(x); + return rb_num_negative_p(x); } #define f_positive_p(x) (!f_negative_p(x)) @@ -202,13 +202,13 @@ f_zero_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L202 #define f_nonzero_p(x) (!f_zero_p(x)) -inline static VALUE +inline static int f_kind_of_p(VALUE x, VALUE c) { - return rb_obj_is_kind_of(x, c); + return (int)rb_obj_is_kind_of(x, c); } -inline static VALUE +inline static int k_numeric_p(VALUE x) { return f_kind_of_p(x, rb_cNumeric); @@ -1209,26 +1209,27 @@ nucomp_eql_p(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/complex.c#L1209 return Qfalse; } -inline static VALUE +inline static int f_signbit(VALUE x) { if (RB_FLOAT_TYPE_P(x)) { double f = RFLOAT_VALUE(x); - return f_boolcast(!isnan(f) && signbit(f)); + return !isnan(f) && signbit(f); } return f_negative_p(x); } -inline static VALUE +inline static int f_tpositive_p(VALUE x) { - return f_boolcast(!f_signbit(x)); + return !f_signbit(x); } static VALUE f_format(VALUE self, VALUE (*func)(VALUE)) { - VALUE s, impos; + VALUE s; + int impos; get_dat1(self); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/