mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Avoid creating unnecessary empty arrays on splat.
But this changes requires `OP_ARYCAT` and `OP_ARYPUSH` to accept `nil` as their first operand. Alternative VMs (e.g. `mruby/c`) that understand mruby bytecode need to be updated.
This commit is contained in:
@@ -956,7 +956,12 @@ gen_values(codegen_scope *s, node *t, int val, int extra)
|
||||
}
|
||||
else {
|
||||
pop_n(n);
|
||||
genop_2(s, OP_ARRAY, cursp(), n);
|
||||
if (n == 0 && is_splat) {
|
||||
genop_1(s, OP_LOADNIL, cursp());
|
||||
}
|
||||
else {
|
||||
genop_2(s, OP_ARRAY, cursp(), n);
|
||||
}
|
||||
push();
|
||||
codegen(s, t->car, VAL);
|
||||
pop(); pop();
|
||||
|
||||
@@ -2441,7 +2441,12 @@ RETRY_TRY_BLOCK:
|
||||
|
||||
CASE(OP_ARYCAT, B) {
|
||||
mrb_value splat = mrb_ary_splat(mrb, regs[a+1]);
|
||||
mrb_ary_concat(mrb, regs[a], splat);
|
||||
if (mrb_nil_p(regs[a])) {
|
||||
regs[a] = splat;
|
||||
}
|
||||
else {
|
||||
mrb_ary_concat(mrb, regs[a], splat);
|
||||
}
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
NEXT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user