From dd8c178a739c980642a5747d655ae4a283f31615 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 5 Jun 2020 11:08:04 +0900 Subject: Use `static const struct mrb_irep each_irep` to ininitalize `each`. --- src/array.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'src/array.c') diff --git a/src/array.c b/src/array.c index 1337736f4..773165a8c 100644 --- a/src/array.c +++ b/src/array.c @@ -1302,30 +1302,38 @@ static const mrb_code each_iseq[] = { OP_RETURN, 0x0 /* OP_RETURN R3 */ }; +static const mrb_sym each_syms[] = { + MRB_SYM(each), + MRB_SYM(to_enum), + MRB_QSYM(aref), + MRB_SYM(call), + MRB_SYM(length), +}; + +static const mrb_irep each_irep = { + .nlocals = 3, + .nregs = 7, + .flags = MRB_ISEQ_NO_FREE | MRB_IREP_NO_FREE, + .iseq = each_iseq, + .pool = NULL, + .syms = each_syms, + .reps = NULL, + .lv = NULL, + .debug_info = NULL, + .ilen = sizeof(each_iseq), + .plen = 0, + .slen = sizeof(each_syms), + .rlen = 1, + .refcnt = 0, +}; + static void init_ary_each(mrb_state *mrb, struct RClass *ary) { struct RProc *p; mrb_method_t m; - mrb_irep *each_irep = (mrb_irep*)mrb_malloc(mrb, sizeof(mrb_irep)); - static const mrb_irep mrb_irep_zero = { 0 }; - mrb_sym *syms; - - *each_irep = mrb_irep_zero; - syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*5); - syms[0] = MRB_SYM(each); - syms[1] = MRB_SYM(to_enum); - syms[2] = MRB_QSYM(aref); - syms[3] = MRB_SYM(call); - syms[4] = MRB_SYM(length); - each_irep->syms = syms; - each_irep->slen = 5; - each_irep->flags = MRB_ISEQ_NO_FREE; - each_irep->iseq = each_iseq; - each_irep->ilen = sizeof(each_iseq); - each_irep->nregs = 7; - each_irep->nlocals = 3; - p = mrb_proc_new(mrb, each_irep); + + p = mrb_proc_new(mrb, &each_irep); p->flags |= MRB_PROC_SCOPE | MRB_PROC_STRICT; MRB_METHOD_FROM_PROC(m, p); mrb_define_method_raw(mrb, ary, MRB_SYM(each), m); -- cgit v1.2.3