diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-09-06 14:35:24 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-09-06 14:35:24 +0900 |
| commit | 2a1e616e4da864bb918583cc6d85a0b130c1ab43 (patch) | |
| tree | 95df896ed6cd5201b42b462b19e010c6036e55d7 /src/class.c | |
| parent | cbfa2b3588732f41669a532f5070cd87cf270319 (diff) | |
| download | mruby-2a1e616e4da864bb918583cc6d85a0b130c1ab43.tar.gz mruby-2a1e616e4da864bb918583cc6d85a0b130c1ab43.zip | |
Avoid calling `mrb_funcall` to invoke `#initialize` from `Class.new`.
If `#initialize` is implemented in C, we don't need stack consuming
`mrb_funcall`.
Diffstat (limited to 'src/class.c')
| -rw-r--r-- | src/class.c | 9 |
1 files changed, 8 insertions, 1 deletions
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); } |
