From 4fcb5e8e4fa687d5645ef49b26cfb61d7bee151b Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 17 Jun 2021 16:53:54 +0900 Subject: 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. --- src/variable.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/variable.c b/src/variable.c index bf421955b..d89295229 100644 --- a/src/variable.c +++ b/src/variable.c @@ -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 -- cgit v1.2.3