summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-22 05:21:12 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-22 05:21:12 +0000
commitb920d9545c6006f97ecf3309878a57f6606d5394 (patch)
tree866bcda089a7cec53fd52e119b1a60b7e4efb745 /complex.c
parentd59bfb2d068212eb0eb649080980d6596cd7410d (diff)
complex.c: optimize f_gt_p some cases
* complex.c (f_gt_p): optimize f_gt_p for specific types of arguments. * internal.h (rb_int_gt, rb_float_gt, rb_rational_cmp): exported. * numeric.c (rb_float_gt): rename from flo_gt and be exported. * numeric.c (rb_int_gt): rename from int_gt and be exported. * rational.c (rb_rational_cmp): rename from nurat_cmp and be exported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/complex.c b/complex.c
index 157201aef3..4737891270 100644
--- a/complex.c
+++ b/complex.c
@@ -97,12 +97,21 @@ f_div(VALUE x, VALUE y)
return rb_funcall(x, '/', 1, y);
}
-inline static VALUE
+inline static int
f_gt_p(VALUE x, VALUE y)
{
- if (FIXNUM_P(x) && FIXNUM_P(y))
- return f_boolcast(FIX2LONG(x) > FIX2LONG(y));
- return rb_funcall(x, '>', 1, y);
+ if (RB_INTEGER_TYPE_P(x)) {
+ if (FIXNUM_P(x) && FIXNUM_P(y))
+ return (SIGNED_VALUE)x > (SIGNED_VALUE)y;
+ return RTEST(rb_int_gt(x, y));
+ }
+ else if (RB_FLOAT_TYPE_P(x))
+ return RTEST(rb_float_gt(x, y));
+ else if (RB_TYPE_P(x, T_RATIONAL)) {
+ int const cmp = rb_cmpint(rb_rational_cmp(x, y), x, y);
+ return cmp > 0;
+ }
+ return RTEST(rb_funcall(x, '>', 1, y));
}
inline static VALUE