Speed up symbol equality comparison

This commit is contained in:
leviongit
2023-01-09 18:54:56 +01:00
parent 9257a61b39
commit af06d54843
2 changed files with 11 additions and 0 deletions
+8
View File
@@ -677,6 +677,13 @@ sym_cmp(mrb_state *mrb, mrb_value s1)
}
}
static mrb_value
sym_eq(mrb_state *mrb, mrb_value self)
{
mrb_value other = mrb_get_arg1(mrb);
return mrb_bool_value(mrb_obj_equal(mrb, self, other));
}
void
mrb_init_symbol(mrb_state *mrb)
{
@@ -691,4 +698,5 @@ mrb_init_symbol(mrb_state *mrb)
mrb_define_method_id(mrb, sym, MRB_SYM(to_sym), mrb_obj_itself, MRB_ARGS_NONE()); /* 15.2.11.3.4 */
mrb_define_method_id(mrb, sym, MRB_SYM(inspect), sym_inspect, MRB_ARGS_NONE()); /* 15.2.11.3.5(x) */
mrb_define_method_id(mrb, sym, MRB_OPSYM(cmp), sym_cmp, MRB_ARGS_REQ(1));
mrb_define_method_id(mrb, sym, MRB_OPSYM(eq), sym_eq, MRB_ARGS_REQ(1));
}
+3
View File
@@ -2662,6 +2662,9 @@ RETRY_TRY_BLOCK:
if (mrb_obj_eq(mrb, regs[a], regs[a+1])) {
SET_TRUE_VALUE(regs[a]);
}
else if (mrb_type(regs[a]) == MRB_TT_SYMBOL) {
SET_FALSE_VALUE(regs[a]);
}
else {
OP_CMP(==,eq);
}