variable.c (const_get): avoid mrb_funcall if possible

Directly call mrb_const_missing() if const_missing is not overridden.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-06-12 23:47:35 +09:00
parent 89f7bb1056
commit 17720c9b7b
3 changed files with 19 additions and 8 deletions
+2
View File
@@ -23,6 +23,8 @@ mrb_value mrb_mod_to_s(mrb_state *, mrb_value);
void mrb_method_added(mrb_state *mrb, struct RClass *c, mrb_sym mid);
mrb_noreturn void mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args);
mrb_method_t mrb_vm_find_method(mrb_state *mrb, struct RClass *c, struct RClass **cp, mrb_sym mid);
mrb_value mrb_mod_const_missing(mrb_state *mrb, mrb_value mod);
mrb_value mrb_const_missing(mrb_state *mrb, mrb_value mod, mrb_sym sym);
#endif
/* debug */
+12 -7
View File
@@ -2486,14 +2486,9 @@ mrb_mod_remove_const(mrb_state *mrb, mrb_value mod)
return val;
}
static mrb_value
mrb_mod_const_missing(mrb_state *mrb, mrb_value mod)
mrb_value
mrb_const_missing(mrb_state *mrb, mrb_value mod, mrb_sym sym)
{
mrb_sym sym;
mrb_get_args(mrb, "n", &sym);
mrb->c->ci->mid = 0;
if (mrb_class_real(mrb_class_ptr(mod)) != mrb->object_class) {
mrb_name_error(mrb, sym, "uninitialized constant %v::%n", mod, sym);
}
@@ -2504,6 +2499,16 @@ mrb_mod_const_missing(mrb_state *mrb, mrb_value mod)
return mrb_nil_value();
}
mrb_value
mrb_mod_const_missing(mrb_state *mrb, mrb_value mod)
{
mrb_sym sym;
mrb_get_args(mrb, "n", &sym);
mrb->c->ci->mid = 0;
return mrb_const_missing(mrb, mod, sym);
}
/* 15.2.2.4.34 */
/*
* call-seq:
+5 -1
View File
@@ -785,8 +785,12 @@ L_RETRY:
retry = TRUE;
goto L_RETRY;
}
mrb_value mod = mrb_obj_value(base);
if (mrb_func_basic_p(mrb, mod, MRB_SYM(const_missing), mrb_mod_const_missing)) {
return mrb_const_missing(mrb, mod, sym);
}
mrb_value name = mrb_symbol_value(sym);
return mrb_funcall_argv(mrb, mrb_obj_value(base), MRB_SYM(const_missing), 1, &name);
return mrb_funcall_argv(mrb, mod, MRB_SYM(const_missing), 1, &name);
}
MRB_API mrb_value