ruby-changes:44699
From: mrkn <ko1@a...>
Date: Mon, 14 Nov 2016 01:43:48 +0900 (JST)
Subject: [ruby-changes:44699] mrkn:r56772 (trunk): complex.c: refactoring
mrkn 2016-11-14 01:43:43 +0900 (Mon, 14 Nov 2016) New Revision: 56772 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56772 Log: complex.c: refactoring * complex.c (f_zero_p): return int rather than VALUE. * complex.c (rb_complex_mul): remove needless negate operations. Modified files: trunk/complex.c Index: complex.c =================================================================== --- complex.c (revision 56771) +++ complex.c (revision 56772) @@ -187,21 +187,17 @@ f_negative_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L187 #define f_positive_p(x) (!f_negative_p(x)) -inline static VALUE +inline static int f_zero_p(VALUE x) { - if (FIXNUM_P(x)) { - return f_boolcast(FIXNUM_ZERO_P(x)); - } - else if (RB_TYPE_P(x, T_BIGNUM)) { - return Qfalse; + if (RB_INTEGER_TYPE_P(x)) { + return FIXNUM_ZERO_P(x); } else if (RB_TYPE_P(x, T_RATIONAL)) { - VALUE num = RRATIONAL(x)->num; - - return f_boolcast(FIXNUM_P(num) && FIXNUM_ZERO_P(num)); + const VALUE num = RRATIONAL(x)->num; + return FIXNUM_ZERO_P(num); } - return rb_funcall(x, id_eqeq_p, 1, ZERO); + return (int)rb_equal(x, ZERO); } #define f_nonzero_p(x) (!f_zero_p(x)) @@ -738,10 +734,10 @@ rb_complex_mul(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/complex.c#L734 get_dat2(self, other); - arzero = !!f_zero_p(areal = adat->real); - aizero = !!f_zero_p(aimag = adat->imag); - brzero = !!f_zero_p(breal = bdat->real); - bizero = !!f_zero_p(bimag = bdat->imag); + arzero = f_zero_p(areal = adat->real); + aizero = f_zero_p(aimag = adat->imag); + brzero = f_zero_p(breal = bdat->real); + bizero = f_zero_p(bimag = bdat->imag); real = f_sub(safe_mul(areal, breal, arzero, brzero), safe_mul(aimag, bimag, aizero, bizero)); imag = f_add(safe_mul(areal, bimag, arzero, bizero), -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/