variable.c: add skip argument to skip base class in lookup.

`mrb_vm_const_get` function looks up the constant first in the base
class, so that fallback `const_get` need not to search from the base.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-06-17 16:53:54 +09:00
parent 63bafca7f5
commit 4fcb5e8e4f
+4 -3
View File
@@ -766,13 +766,14 @@ mod_const_check(mrb_state *mrb, mrb_value mod)
}
static mrb_value
const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym)
const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym, mrb_bool skip)
{
struct RClass *c = base;
mrb_value v;
mrb_bool retry = FALSE;
mrb_value name;
if (skip) c = c->super;
L_RETRY:
while (c) {
if (!MRB_FLAG_TEST(c, MRB_FL_CLASS_IS_PREPENDED) && c->iv) {
@@ -794,7 +795,7 @@ MRB_API mrb_value
mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
{
mod_const_check(mrb, mod);
return const_get(mrb, mrb_class_ptr(mod), sym);
return const_get(mrb, mrb_class_ptr(mod), sym, FALSE);
}
mrb_value
@@ -829,7 +830,7 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
}
proc = proc->upper;
}
return const_get(mrb, c, sym);
return const_get(mrb, c, sym, TRUE);
}
MRB_API void