summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-08-16 16:36:13 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-08-16 16:42:40 +0900
commit06c7ff06662440a900c06cda5646b7090ab9d8c9 (patch)
tree8ebaeb4292095a8a5df9def16fd021e3e07e45c2 /src
parentfa8515bc2c22ad1b1c7688cf0201022702f6a22f (diff)
downloadmruby-06c7ff06662440a900c06cda5646b7090ab9d8c9.tar.gz
mruby-06c7ff06662440a900c06cda5646b7090ab9d8c9.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/vm.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/vm.c b/src/vm.c
index 12805a8e4..458b9249e 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -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;
}