vm_eval.c: reuse found method entry
* vm_eval.c (check_funcall_missing): reuse found method entry instead of searching same entry repeatedly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
84586cc4b4
commit
dc9c55d611
39
vm_eval.c
39
vm_eval.c
@ -347,8 +347,10 @@ rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct rescue_funcall_args {
|
struct rescue_funcall_args {
|
||||||
|
VALUE defined_class;
|
||||||
VALUE recv;
|
VALUE recv;
|
||||||
ID mid;
|
ID mid;
|
||||||
|
const rb_method_entry_t *me;
|
||||||
int argc;
|
int argc;
|
||||||
const VALUE *argv;
|
const VALUE *argv;
|
||||||
};
|
};
|
||||||
@ -356,14 +358,9 @@ struct rescue_funcall_args {
|
|||||||
static VALUE
|
static VALUE
|
||||||
check_funcall_exec(struct rescue_funcall_args *args)
|
check_funcall_exec(struct rescue_funcall_args *args)
|
||||||
{
|
{
|
||||||
VALUE new_args = rb_ary_new4(args->argc, args->argv);
|
return call_method_entry(GET_THREAD(), args->defined_class,
|
||||||
VALUE ret;
|
args->recv, idMethodMissing,
|
||||||
|
args->me, args->argc, args->argv);
|
||||||
rb_ary_unshift(new_args, ID2SYM(args->mid));
|
|
||||||
ret = rb_funcall2(args->recv, idMethodMissing,
|
|
||||||
args->argc+1, RARRAY_CONST_PTR(new_args));
|
|
||||||
RB_GC_GUARD(new_args);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -390,21 +387,27 @@ check_funcall_callable(rb_thread_t *th, const rb_callable_method_entry_t *me)
|
|||||||
static VALUE
|
static VALUE
|
||||||
check_funcall_missing(rb_thread_t *th, VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv)
|
check_funcall_missing(rb_thread_t *th, VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv)
|
||||||
{
|
{
|
||||||
if (rb_method_basic_definition_p(klass, idMethodMissing)) {
|
struct rescue_funcall_args args;
|
||||||
return Qundef;
|
VALUE ret = Qundef;
|
||||||
}
|
const rb_method_entry_t *const me =
|
||||||
else {
|
method_entry_get(klass, idMethodMissing, &args.defined_class);
|
||||||
struct rescue_funcall_args args;
|
if (me && !METHOD_ENTRY_BASIC(me)) {
|
||||||
|
VALUE argbuf, *new_args = ALLOCV_N(VALUE, argbuf, argc+1);
|
||||||
|
|
||||||
|
new_args[0] = ID2SYM(mid);
|
||||||
|
MEMCPY(new_args+1, argv, VALUE, argc);
|
||||||
th->method_missing_reason = MISSING_NOENTRY;
|
th->method_missing_reason = MISSING_NOENTRY;
|
||||||
args.recv = recv;
|
args.recv = recv;
|
||||||
|
args.me = me;
|
||||||
args.mid = mid;
|
args.mid = mid;
|
||||||
args.argc = argc;
|
args.argc = argc + 1;
|
||||||
args.argv = argv;
|
args.argv = new_args;
|
||||||
return rb_rescue2(check_funcall_exec, (VALUE)&args,
|
ret = rb_rescue2(check_funcall_exec, (VALUE)&args,
|
||||||
check_funcall_failed, (VALUE)&args,
|
check_funcall_failed, (VALUE)&args,
|
||||||
rb_eNoMethodError, (VALUE)0);
|
rb_eNoMethodError, (VALUE)0);
|
||||||
|
ALLOCV_END(argbuf);
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user