ruby-changes:61457
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Wed, 3 Jun 2020 16:14:04 +0900 (JST)
Subject: [ruby-changes:61457] ec87a58d55 (master): vm_invoke_block: eliminate goto
https://git.ruby-lang.org/ruby.git/commit/?id=ec87a58d55 From ec87a58d556c83bbec44c2df8444d95df56379a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Tue, 26 May 2020 10:14:17 +0900 Subject: vm_invoke_block: eliminate goto Use recursion for better readability. diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 398edbf..5e9df01 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2725,7 +2725,7 @@ vm_call_opt_send(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2725 return vm_call_method(ec, reg_cfp, calling, (CALL_DATA)&cd); } -static inline VALUE vm_invoke_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct rb_calling_info *calling, const struct rb_callinfo *ci, VALUE block_handler); +static inline VALUE vm_invoke_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct rb_calling_info *calling, const struct rb_callinfo *ci, bool is_lambda, VALUE block_handler); NOINLINE(static VALUE vm_invoke_block_opt_call(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, @@ -2741,7 +2741,7 @@ vm_invoke_block_opt_call(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2741 if (argc > 0) MEMMOVE(&TOPN(argc), &TOPN(argc-1), VALUE, argc); DEC_SP(1); - return vm_invoke_block(ec, reg_cfp, calling, ci, block_handler); + return vm_invoke_block(ec, reg_cfp, calling, ci, false, block_handler); } static VALUE @@ -3457,22 +3457,28 @@ vm_proc_to_block_handler(VALUE procval) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3457 return Qundef; } +static VALUE +vm_invoke_proc_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, + struct rb_calling_info *calling, const struct rb_callinfo *ci, + VALUE block_handler) +{ + return vm_invoke_block(ec, reg_cfp, calling, ci, + block_proc_is_lambda(VM_BH_TO_PROC(block_handler)), + vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler))); +} + static inline VALUE vm_invoke_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, - struct rb_calling_info *calling, const struct rb_callinfo *ci, VALUE block_handler) + struct rb_calling_info *calling, const struct rb_callinfo *ci, + bool is_lambda, VALUE block_handler) { - int is_lambda = FALSE; - - again: switch (vm_block_handler_type(block_handler)) { case block_handler_type_iseq: return vm_invoke_iseq_block(ec, reg_cfp, calling, ci, is_lambda, block_handler); case block_handler_type_ifunc: return vm_invoke_ifunc_block(ec, reg_cfp, calling, ci, block_handler); case block_handler_type_proc: - is_lambda = block_proc_is_lambda(VM_BH_TO_PROC(block_handler)); - block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler)); - goto again; + return vm_invoke_proc_block(ec, reg_cfp, calling, ci, block_handler); case block_handler_type_symbol: return vm_invoke_symbol_block(ec, reg_cfp, calling, ci, block_handler); } @@ -4040,7 +4046,7 @@ vm_invokeblock_i( https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4046 rb_vm_localjump_error("no block given (yield)", Qnil, 0); } else { - return vm_invoke_block(ec, GET_CFP(), calling, ci, block_handler); + return vm_invoke_block(ec, GET_CFP(), calling, ci, false, block_handler); } } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/