From 3e3318112f94b7d59eb57f7e28800a1b5290ae6b Mon Sep 17 00:00:00 2001 From: mrkn Date: Sun, 13 Nov 2016 16:22:08 +0000 Subject: complex.c: refactoring and small optimization * complex.c (nucomp_expt): optimize the access to the numerator and denominator of a rational number. * complex.c (k_rational_p): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- complex.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'complex.c') diff --git a/complex.c b/complex.c index 11171e3e02..e2a7efb262 100644 --- a/complex.c +++ b/complex.c @@ -237,12 +237,6 @@ k_numeric_p(VALUE x) return f_kind_of_p(x, rb_cNumeric); } - -inline static VALUE -k_rational_p(VALUE x) -{ - return f_kind_of_p(x, rb_cRational); -} #define k_exact_p(x) (!RB_FLOAT_TYPE_P(x)) #define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x)) @@ -895,8 +889,8 @@ nucomp_expt(VALUE self, VALUE other) if (k_numeric_p(other) && k_exact_zero_p(other)) return f_complex_new_bang1(CLASS_OF(self), ONE); - if (k_rational_p(other) && f_one_p(f_denominator(other))) - other = f_numerator(other); /* c14n */ + if (RB_TYPE_P(other, T_RATIONAL) && RRATIONAL(other)->den == LONG2FIX(1)) + other = RRATIONAL(other)->num; /* c14n */ if (RB_TYPE_P(other, T_COMPLEX)) { get_dat1(other); -- cgit v1.2.3