From 975e0ef8581e7713fc316e71a7e96a0afb20bbae Mon Sep 17 00:00:00 2001 From: mrkn Date: Sun, 13 Nov 2016 16:43:43 +0000 Subject: complex.c: refactoring * complex.c (f_zero_p): return int rather than VALUE. * complex.c (rb_complex_mul): remove needless negate operations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- complex.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'complex.c') diff --git a/complex.c b/complex.c index 0f9a8d314d..998addb460 100644 --- a/complex.c +++ b/complex.c @@ -187,21 +187,17 @@ f_negative_p(VALUE x) #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) 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), -- cgit v1.2.3