1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
mrkn 2016-11-22 05:21:12 +00:00
parent d59bfb2d06
commit b920d9545c
4 changed files with 25 additions and 13 deletions

View file

@ -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

View file

@ -1178,6 +1178,8 @@ VALUE rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode);
VALUE rb_int2str(VALUE num, int base);
VALUE rb_dbl_hash(double d);
VALUE rb_fix_plus(VALUE x, VALUE y);
VALUE rb_int_gt(VALUE x, VALUE y);
VALUE rb_float_gt(VALUE x, VALUE y);
VALUE rb_int_ge(VALUE x, VALUE y);
enum ruby_num_rounding_mode rb_num_get_rounding_option(VALUE opts);
double rb_int_fdiv_double(VALUE x, VALUE y);
@ -1385,6 +1387,7 @@ VALUE rb_lcm(VALUE x, VALUE y);
VALUE rb_rational_reciprocal(VALUE x);
VALUE rb_cstr_to_rat(const char *, int);
VALUE rb_rational_abs(VALUE self);
VALUE rb_rational_cmp(VALUE self, VALUE other);
/* re.c */
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);

View file

@ -1494,8 +1494,8 @@ flo_cmp(VALUE x, VALUE y)
* implementation-dependent value is returned.
*/
static VALUE
flo_gt(VALUE x, VALUE y)
VALUE
rb_float_gt(VALUE x, VALUE y)
{
double a, b;
@ -4074,8 +4074,8 @@ fix_gt(VALUE x, VALUE y)
}
}
static VALUE
int_gt(VALUE x, VALUE y)
VALUE
rb_int_gt(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_gt(x, y);
@ -5270,7 +5270,7 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "===", rb_int_equal, 1);
rb_define_method(rb_cInteger, "==", rb_int_equal, 1);
rb_define_method(rb_cInteger, ">", int_gt, 1);
rb_define_method(rb_cInteger, ">", rb_int_gt, 1);
rb_define_method(rb_cInteger, ">=", rb_int_ge, 1);
rb_define_method(rb_cInteger, "<", int_lt, 1);
rb_define_method(rb_cInteger, "<=", int_le, 1);
@ -5411,7 +5411,7 @@ Init_Numeric(void)
rb_define_method(rb_cFloat, "==", flo_eq, 1);
rb_define_method(rb_cFloat, "===", flo_eq, 1);
rb_define_method(rb_cFloat, "<=>", flo_cmp, 1);
rb_define_method(rb_cFloat, ">", flo_gt, 1);
rb_define_method(rb_cFloat, ">", rb_float_gt, 1);
rb_define_method(rb_cFloat, ">=", flo_ge, 1);
rb_define_method(rb_cFloat, "<", flo_lt, 1);
rb_define_method(rb_cFloat, "<=", flo_le, 1);

View file

@ -1063,8 +1063,8 @@ nurat_expt(VALUE self, VALUE other)
* Rational(1,3) <=> 1 #=> -1
* Rational(1,3) <=> 0.3 #=> 1
*/
static VALUE
nurat_cmp(VALUE self, VALUE other)
VALUE
rb_rational_cmp(VALUE self, VALUE other)
{
if (RB_INTEGER_TYPE_P(other)) {
{
@ -2648,7 +2648,7 @@ Init_Rational(void)
rb_define_method(rb_cRational, "fdiv", nurat_fdiv, 1);
rb_define_method(rb_cRational, "**", nurat_expt, 1);
rb_define_method(rb_cRational, "<=>", nurat_cmp, 1);
rb_define_method(rb_cRational, "<=>", rb_rational_cmp, 1);
rb_define_method(rb_cRational, "==", nurat_eqeq_p, 1);
rb_define_method(rb_cRational, "coerce", nurat_coerce, 1);