From 2a1e616e4da864bb918583cc6d85a0b130c1ab43 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 6 Sep 2017 14:35:24 +0900 Subject: Avoid calling `mrb_funcall` to invoke `#initialize` from `Class.new`. If `#initialize` is implemented in C, we don't need stack consuming `mrb_funcall`. --- src/class.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/class.c b/src/class.c index e3888001b..44121bce6 100644 --- a/src/class.c +++ b/src/class.c @@ -1531,11 +1531,18 @@ mrb_instance_new(mrb_state *mrb, mrb_value cv) mrb_value *argv; mrb_int argc; mrb_sym init; + struct RProc *p; mrb_get_args(mrb, "*&", &argv, &argc, &blk); obj = mrb_instance_alloc(mrb, cv); init = mrb_intern_lit(mrb, "initialize"); - if (!mrb_func_basic_p(mrb, obj, init, mrb_bob_init)) { + p = mrb_method_search(mrb, mrb_class(mrb, obj), init); + if (MRB_PROC_CFUNC_P(p)) { + if (p->body.func != mrb_bob_init) { + p->body.func(mrb, obj); + } + } + else { mrb_funcall_with_block(mrb, obj, init, argc, argv, blk); } -- cgit v1.2.3