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

Hoisted out ensure_cmp which checks the comparison succeeded

This commit is contained in:
Nobuyoshi Nakada 2020-10-02 21:30:07 +09:00
parent 74aaa8e7ab
commit dd77796f1c
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -467,17 +467,23 @@ rb_num_coerce_cmp(VALUE x, VALUE y, ID func)
return Qnil;
}
static VALUE
ensure_cmp(VALUE c, VALUE x, VALUE y)
{
if (NIL_P(c)) rb_cmperr(x, y);
return c;
}
VALUE
rb_num_coerce_relop(VALUE x, VALUE y, ID func)
{
VALUE c, x0 = x, y0 = y;
VALUE x0 = x, y0 = y;
if (!do_coerce(&x, &y, FALSE) ||
NIL_P(c = rb_funcall(x, func, 1, y))) {
if (!do_coerce(&x, &y, FALSE)) {
rb_cmperr(x0, y0);
return Qnil; /* not reached */
UNREACHABLE_RETURN(Qnil);
}
return c;
return ensure_cmp(rb_funcall(x, func, 1, y), x0, y0);
}
NORETURN(static VALUE num_sadded(VALUE x, VALUE name));
@ -1518,9 +1524,7 @@ flo_cmp(VALUE x, VALUE y)
MJIT_FUNC_EXPORTED int
rb_float_cmp(VALUE x, VALUE y)
{
VALUE c = flo_cmp(x, y);
if (NIL_P(c)) rb_cmperr(x, y);
return NUM2INT(c);
return NUM2INT(ensure_cmp(flo_cmp(x, y), x, y));
}
/*
@ -5093,7 +5097,7 @@ int_upto(VALUE from, VALUE to)
rb_yield(i);
i = rb_funcall(i, '+', 1, INT2FIX(1));
}
if (NIL_P(c)) rb_cmperr(i, to);
ensure_cmp(c, i, to);
}
return from;
}