diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-22 05:21:12 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-22 05:21:12 +0000 |
commit | f80c76f92efd79cc2918b8e57c8a400c7583caf1 (patch) | |
tree | 866bcda089a7cec53fd52e119b1a60b7e4efb745 /complex.c | |
parent | c3b3a34c03df4b65154700132ba5c375dffa8802 (diff) | |
download | ruby-f80c76f92efd79cc2918b8e57c8a400c7583caf1.tar.gz |
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.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -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 |