diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-07 19:18:49 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-07 19:18:49 +0000 |
commit | 7fd11834676eb4df34f7160aed1cdf798e60d0b9 (patch) | |
tree | a9d327ea998ac6a9e97211a9df0f101b9cb8a5e8 /compile.c | |
parent | bb8f6ac0feafa2d7045e05151346d0f16279c435 (diff) | |
download | ruby-7fd11834676eb4df34f7160aed1cdf798e60d0b9.tar.gz |
Speedup `block.call` [Feature #14330]
* insns.def (getblockparamproxy): introduce new instruction to return
the `rb_block_param_proxy` object if possible. This object responds
to `call` method and invoke given block (completely similar to `yield`).
* method.h (OPTIMIZED_METHOD_TYPE_BLOCK_CALL): add new optimized call type
which is for `rb_block_param_proxy.cal`.
* vm_insnhelper.c (vm_call_method_each_type): ditto.
* vm_insnhelper.c (vm_call_opt_block_call): ditto.
* vm_core.h (BOP_CALL, PROC_REDEFINED_OP_FLAG): add check for `Proc#call`
redefinition.
* compile.c (iseq_compile_each0): compile to use new insn
`getblockparamproxy` for method call.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -1399,6 +1399,21 @@ iseq_local_block_param_p(const rb_iseq_t *iseq, unsigned int idx, unsigned int l } } +static int +iseq_block_param_id_p(const rb_iseq_t *iseq, ID id, int *pidx, int *plevel) +{ + int level, ls; + int idx = get_dyna_var_idx(iseq, id, &level, &ls); + if (iseq_local_block_param_p(iseq, ls - idx, level)) { + *pidx = ls - idx; + *plevel = level; + return TRUE; + } + else { + return FALSE; + } +} + static void iseq_add_getlocal(rb_iseq_t *iseq, LINK_ANCHOR *const seq, int line, int idx, int level) { @@ -6159,7 +6174,17 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in #endif /* receiver */ if (type == NODE_CALL || type == NODE_OPCALL || type == NODE_QCALL) { - CHECK(COMPILE(recv, "recv", node->nd_recv)); + int idx, level; + + if (mid == idCall && + nd_type(node->nd_recv) == NODE_LVAR && + iseq_block_param_id_p(iseq, node->nd_recv->nd_vid, &idx, &level)) { + ADD_INSN2(recv, nd_line(node->nd_recv), getblockparamproxy, INT2FIX(idx + VM_ENV_DATA_SIZE - 1), INT2FIX(level)); + } + else { + CHECK(COMPILE(recv, "recv", node->nd_recv)); + } + if (type == NODE_QCALL) { else_label = NEW_LABEL(line); end_label = NEW_LABEL(line); |