summaryrefslogtreecommitdiffhomepage
path: root/src/class.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-06-20 11:07:07 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-10-12 16:21:16 +0900
commit167a747a414860149858f1efef51ea3c3afe49e0 (patch)
treea3136547cb432b7c1b21d288c00a2bb082e2b18e /src/class.c
parentcfc958b01a0d0c33877d5773d15745021f1dfe13 (diff)
downloadmruby-167a747a414860149858f1efef51ea3c3afe49e0.tar.gz
mruby-167a747a414860149858f1efef51ea3c3afe49e0.zip
Constify `irep` struct for `Class#new`.
Diffstat (limited to 'src/class.c')
-rw-r--r--src/class.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/class.c b/src/class.c
index 38b9c6740..c48229d8a 100644
--- a/src/class.c
+++ b/src/class.c
@@ -2309,27 +2309,20 @@ static const mrb_code new_iseq[] = {
OP_RETURN, 0x0 /* OP_RETURN R0 */
};
+const mrb_sym new_syms[] = { MRB_SYM(allocate), MRB_SYM(initialize) };
+static const mrb_irep new_irep = {
+ 3, 6, MRB_IREP_STATIC,
+ new_iseq, NULL, new_syms, NULL, NULL, NULL,
+ sizeof(new_iseq), 0, 2, 0, 0,
+};
+
static void
init_class_new(mrb_state *mrb, struct RClass *cls)
{
struct RProc *p;
mrb_method_t m;
- mrb_irep *new_irep = (mrb_irep*)mrb_malloc(mrb, sizeof(mrb_irep));
- mrb_sym *syms;
- static const mrb_irep mrb_irep_zero = { 0 };
-
- *new_irep = mrb_irep_zero;
- syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*2);
- syms[0] = MRB_SYM(allocate);
- syms[1] = MRB_SYM(initialize);
- new_irep->syms = syms;
- new_irep->slen = 2;
- new_irep->flags = MRB_ISEQ_NO_FREE;
- new_irep->iseq = new_iseq;
- new_irep->ilen = sizeof(new_iseq);
- new_irep->nregs = 6;
- new_irep->nlocals = 3;
- p = mrb_proc_new(mrb, new_irep);
+
+ p = mrb_proc_new(mrb, &new_irep);
MRB_METHOD_FROM_PROC(m, p);
mrb_define_method_raw(mrb, cls, MRB_SYM(new), m);
}