summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-06-05 11:08:04 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-10-12 16:21:06 +0900
commitdd8c178a739c980642a5747d655ae4a283f31615 (patch)
treee6a2b781c1cba0d008cc7bd35044f9ca8bacfde3
parent029c7c1116acc95937f02e15debd1989ae0b7382 (diff)
downloadmruby-dd8c178a739c980642a5747d655ae4a283f31615.tar.gz
mruby-dd8c178a739c980642a5747d655ae4a283f31615.zip
Use `static const struct mrb_irep each_irep` to ininitalize `each`.
-rw-r--r--src/array.c46
1 files changed, 27 insertions, 19 deletions
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);