From 8455c41a7453b98f8a49518652c73a86616110ca Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 27 Oct 2025 08:24:07 +0900 Subject: [PATCH] mruby-compiler: combine variable declaration with initialization --- mrbgems/mruby-compiler/core/codegen.c | 15 ++++++--------- mrbgems/mruby-compiler/core/parse.y | 13 ++++--------- mrbgems/mruby-compiler/core/y.tab.c | 13 ++++--------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index f008087cd..d8e2ce4fb 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -2624,16 +2624,13 @@ nosplat(node *t) static mrb_sym attrsym(codegen_scope *s, mrb_sym a) { - const char *name; mrb_int len; - char *name2; - - name = mrb_sym_name_len(s->mrb, a, &len); - name2 = (char*)codegen_palloc(s, - (size_t)len - + 1 /* '=' */ - + 1 /* '\0' */ - ); + const char *name = mrb_sym_name_len(s->mrb, a, &len); + char *name2 = (char*)codegen_palloc(s, + (size_t)len + + 1 /* '=' */ + + 1 /* '\0' */ + ); mrb_assert_int_fit(mrb_int, len, size_t, SIZE_MAX); memcpy(name2, name, (size_t)len); name2[len] = '='; diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 817daa59a..49f7422b8 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -7385,14 +7385,9 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c) return mrb_load_exec(mrb, mrb_parse_file_continue(mrb, fp, leading.b, bufsize, c), c); } else { - mrb_int binsize; - uint8_t *bin; - mrb_value bin_obj = mrb_nil_value(); /* temporary string object */ - mrb_value result; - - binsize = bin_to_uint32(leading.h.binary_size); - bin_obj = mrb_str_new(mrb, NULL, binsize); - bin = (uint8_t*)RSTRING_PTR(bin_obj); + mrb_int binsize = bin_to_uint32(leading.h.binary_size); + mrb_value bin_obj = mrb_str_new(mrb, NULL, binsize); + uint8_t *bin = (uint8_t*)RSTRING_PTR(bin_obj); if ((size_t)binsize > bufsize) { memcpy(bin, leading.b, bufsize); if (fread(bin + bufsize, binsize - bufsize, 1, fp) == 0) { @@ -7401,7 +7396,7 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c) } } - result = mrb_load_irep_buf_cxt(mrb, bin, binsize, c); + mrb_value result = mrb_load_irep_buf_cxt(mrb, bin, binsize, c); if (mrb_string_p(bin_obj)) mrb_str_resize(mrb, bin_obj, 0); return result; } diff --git a/mrbgems/mruby-compiler/core/y.tab.c b/mrbgems/mruby-compiler/core/y.tab.c index 8766c381b..55257d8d7 100644 --- a/mrbgems/mruby-compiler/core/y.tab.c +++ b/mrbgems/mruby-compiler/core/y.tab.c @@ -14214,14 +14214,9 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c) return mrb_load_exec(mrb, mrb_parse_file_continue(mrb, fp, leading.b, bufsize, c), c); } else { - mrb_int binsize; - uint8_t *bin; - mrb_value bin_obj = mrb_nil_value(); /* temporary string object */ - mrb_value result; - - binsize = bin_to_uint32(leading.h.binary_size); - bin_obj = mrb_str_new(mrb, NULL, binsize); - bin = (uint8_t*)RSTRING_PTR(bin_obj); + mrb_int binsize = bin_to_uint32(leading.h.binary_size); + mrb_value bin_obj = mrb_str_new(mrb, NULL, binsize); + uint8_t *bin = (uint8_t*)RSTRING_PTR(bin_obj); if ((size_t)binsize > bufsize) { memcpy(bin, leading.b, bufsize); if (fread(bin + bufsize, binsize - bufsize, 1, fp) == 0) { @@ -14230,7 +14225,7 @@ mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c) } } - result = mrb_load_irep_buf_cxt(mrb, bin, binsize, c); + mrb_value result = mrb_load_irep_buf_cxt(mrb, bin, binsize, c); if (mrb_string_p(bin_obj)) mrb_str_resize(mrb, bin_obj, 0); return result; }