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.
parent 63bafca7
...@@ -766,13 +766,14 @@ mod_const_check(mrb_state *mrb, mrb_value mod) ...@@ -766,13 +766,14 @@ mod_const_check(mrb_state *mrb, mrb_value mod)
} }
static mrb_value 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; struct RClass *c = base;
mrb_value v; mrb_value v;
mrb_bool retry = FALSE; mrb_bool retry = FALSE;
mrb_value name; mrb_value name;
if (skip) c = c->super;
L_RETRY: L_RETRY:
while (c) { while (c) {
if (!MRB_FLAG_TEST(c, MRB_FL_CLASS_IS_PREPENDED) && c->iv) { if (!MRB_FLAG_TEST(c, MRB_FL_CLASS_IS_PREPENDED) && c->iv) {
...@@ -794,7 +795,7 @@ MRB_API mrb_value ...@@ -794,7 +795,7 @@ MRB_API mrb_value
mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym) mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
{ {
mod_const_check(mrb, mod); 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 mrb_value
...@@ -829,7 +830,7 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym) ...@@ -829,7 +830,7 @@ mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
} }
proc = proc->upper; proc = proc->upper;
} }
return const_get(mrb, c, sym); return const_get(mrb, c, sym, TRUE);
} }
MRB_API void MRB_API void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment