Speed up symbol equality comparison - #6191
Conversation
| if (mrb_obj_eq(mrb, regs[a], regs[a+1])) { | ||
| SET_TRUE_VALUE(regs[a]); | ||
| } | ||
| else if (mrb_type(regs[a]) == MRB_TT_SYMBOL) { |
There was a problem hiding this comment.
Thank you for the pull-request. This is a nice idea. But if the condition is mrb_immediate_p(regs[a]), equalify comparison will be (slightly) faster not only for symbols, but other immediate values such as integers and float numbers.
There was a problem hiding this comment.
this would unfortunately break some test cases, as it means that some (e.g. Integer#==(Rational)) equality checks are never performed.
| 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)); |
There was a problem hiding this comment.
I don't think this sym_eq change would improve the performance, since mrb_obj_equal_m (that defines Object#==) has exactly the same implementation. Should be removed from the PR.
There was a problem hiding this comment.
Symbol inherits the == method from Comparable which does a lexical comparison. a new commit will override == to use mrb_obj_equal_m. (or should i make a separate pr for this?)
No description provided.