object.c (mrb_equal): shortcut per object comparison.

To reduce the chance to call mrb_funcall(), which is heavy and
unfriendly to fiber context switches.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-08-01 16:24:48 +09:00
parent 585d80e0a7
commit 4fb018d407
+6 -4
View File
@@ -58,13 +58,15 @@ mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE;
#ifndef MRB_NO_FLOAT
/* value mixing with integer and float */
if (mrb_integer_p(obj1)) {
if (mrb_float_p(obj2) && (mrb_float)mrb_integer(obj1) == mrb_float(obj2))
if (mrb_integer_p(obj1) && mrb_float_p(obj2)) {
if ((mrb_float)mrb_integer(obj1) == mrb_float(obj2))
return TRUE;
return FALSE;
}
else if (mrb_float_p(obj1)) {
if (mrb_integer_p(obj2) && mrb_float(obj1) == (mrb_float)mrb_integer(obj2))
else if (mrb_float_p(obj1) && mrb_integer_p(obj2)) {
if (mrb_float(obj1) == (mrb_float)mrb_integer(obj2))
return TRUE;
return FALSE;
}
#endif
result = mrb_funcall_id(mrb, obj1, MRB_OPSYM(eq), 1, obj2);