aboutsummaryrefslogtreecommitdiffstats
path: root/insns.def
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-07 19:18:49 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-07 19:18:49 +0000
commita86fd7b1385b87525b89d286dde4963d23930202 (patch)
treea9d327ea998ac6a9e97211a9df0f101b9cb8a5e8 /insns.def
parente39aaf5479a359525e7b3b1c26d50f734f8915f8 (diff)
downloadruby-a86fd7b1385b87525b89d286dde4963d23930202.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 'insns.def')
-rw-r--r--insns.def48
1 files changed, 48 insertions, 0 deletions
diff --git a/insns.def b/insns.def
index bab9d14488..f9375b7c0a 100644
--- a/insns.def
+++ b/insns.def
@@ -129,6 +129,54 @@ setblockparam
/**
@c variable
+ @e Get special proxy object which only responds to `call` method if the block parameter
+ represents a iseq/ifunc block. Otherwise, same as `getblockparam`.
+ @j ブロックパラメータが iseq/ifunc ブロックであれば、特殊なプロキシオブジェクトを取得する。
+ */
+DEFINE_INSN
+getblockparamproxy
+(lindex_t idx, rb_num_t level)
+()
+(VALUE val)
+{
+ const VALUE *ep = vm_get_ep(GET_EP(), level);
+ VM_ASSERT(VM_ENV_LOCAL_P(ep));
+
+ if (!VM_ENV_FLAGS(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM)) {
+ VALUE block_handler = VM_ENV_BLOCK_HANDLER(ep);
+
+ if (block_handler) {
+ switch (vm_block_handler_type(block_handler)) {
+ case block_handler_type_iseq:
+ case block_handler_type_ifunc:
+ val = rb_block_param_proxy;
+ break;
+ case block_handler_type_symbol:
+ val = rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler));
+ goto INSN_LABEL(set);
+ case block_handler_type_proc:
+ val = VM_BH_TO_PROC(block_handler);
+ goto INSN_LABEL(set);
+ default:
+ VM_UNREACHABLE(getblockparamproxy);
+ }
+ }
+ else {
+ val = Qnil;
+ INSN_LABEL(set):
+ vm_env_write(ep, -(int)idx, val);
+ VM_ENV_FLAGS_SET(ep, VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM);
+ }
+ }
+ else {
+ val = *(ep - idx);
+ RB_DEBUG_COUNTER_INC(lvar_get);
+ (void)RB_DEBUG_COUNTER_INC_IF(lvar_get_dynamic, level > 0);
+ }
+}
+
+/**
+ @c variable
@e Get value of special local variable ($~, $_, ..).
@j 特殊なローカル変数($~, $_, ...)の値を得る。
*/