diff options
author | Koichi Sasada <ko1@atdot.net> | 2021-11-18 11:01:31 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2021-11-19 08:32:39 +0900 |
commit | 82ea2870188d66aa75a99f03b4e7fdd1750aa196 (patch) | |
tree | 6ae732893312619a03e8dee23418a52df784d1f8 /compile.c | |
parent | be71c95b88019a1ca7a030a757ce343b743d8aff (diff) |
optimize `Struct` getter/setter
Introduce new optimized method type
`OPTIMIZED_METHOD_TYPE_STRUCT_AREF/ASET` with index information.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5131
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 95 |
1 files changed, 0 insertions, 95 deletions
@@ -10588,101 +10588,6 @@ rb_local_defined(ID id, const rb_iseq_t *iseq) return 0; } -static int -caller_location(VALUE *path, VALUE *realpath) -{ - const rb_execution_context_t *ec = GET_EC(); - const rb_control_frame_t *const cfp = - rb_vm_get_ruby_level_next_cfp(ec, ec->cfp); - - if (cfp) { - int line = rb_vm_get_sourceline(cfp); - *path = rb_iseq_path(cfp->iseq); - *realpath = rb_iseq_realpath(cfp->iseq); - return line; - } - else { - *path = rb_fstring_lit("<compiled>"); - *realpath = *path; - return 1; - } -} - -typedef struct { - VALUE arg; - VALUE func; - int line; -} accessor_args; - -static const rb_iseq_t * -method_for_self(VALUE name, VALUE arg, const struct rb_builtin_function *func, - void (*build)(rb_iseq_t *, LINK_ANCHOR *, const void *)) -{ - VALUE path, realpath; - accessor_args acc; - - acc.arg = arg; - acc.func = (VALUE)func; - acc.line = caller_location(&path, &realpath); - struct rb_iseq_new_with_callback_callback_func *ifunc = - rb_iseq_new_with_callback_new_callback(build, &acc); - return rb_iseq_new_with_callback(ifunc, - rb_sym2str(name), path, realpath, - INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0); -} - -static void -for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a) -{ - const accessor_args *const args = (void *)a; - const int line = args->line; - struct rb_iseq_constant_body *const body = iseq->body; - - iseq_set_local_table(iseq, 0); - body->param.lead_num = 0; - body->param.size = 0; - - NODE dummy_line_node = generate_dummy_line_node(line, -1); - ADD_INSN1(ret, &dummy_line_node, putobject, args->arg); - ADD_INSN1(ret, &dummy_line_node, invokebuiltin, args->func); -} - -static void -for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a) -{ - const accessor_args *const args = (void *)a; - const int line = args->line; - struct rb_iseq_constant_body *const body = iseq->body; - static const ID vars[] = {1, idUScore}; - - iseq_set_local_table(iseq, vars); - body->param.lead_num = 1; - body->param.size = 1; - - NODE dummy_line_node = generate_dummy_line_node(line, -1); - ADD_GETLOCAL(ret, &dummy_line_node, numberof(vars)-1, 0); - ADD_INSN1(ret, &dummy_line_node, putobject, args->arg); - ADD_INSN1(ret, &dummy_line_node, invokebuiltin, args->func); -} - -/* - * func (index) -> (value) - */ -const rb_iseq_t * -rb_method_for_self_aref(VALUE name, VALUE arg, const struct rb_builtin_function *func) -{ - return method_for_self(name, arg, func, for_self_aref); -} - -/* - * func (index, value) -> (value) - */ -const rb_iseq_t * -rb_method_for_self_aset(VALUE name, VALUE arg, const struct rb_builtin_function *func) -{ - return method_for_self(name, arg, func, for_self_aset); -} - /* ISeq binary format */ #ifndef IBF_ISEQ_DEBUG |