aboutsummaryrefslogtreecommitdiffstats
path: root/prism_compile.c
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-11-29 15:02:32 -0500
committerJemma Issroff <jemmaissroff@gmail.com>2023-11-29 16:20:30 -0500
commit8234763816eecd42da3b5e893cd236b64e6fc0fb (patch)
tree06582ae779605f2862514e81468c889d37a9374e /prism_compile.c
parent853fd44745241398d182d2af3ebdea10640ebf2e (diff)
downloadruby-8234763816eecd42da3b5e893cd236b64e6fc0fb.tar.gz
[PRISM] Compile empty array as newarray 0
Prior to this commit, we were compiling an empty array as a duparray of [] which meant we were allocating a new value unnecessarily. With this commit, we emit a newarray with size 0 instead.
Diffstat (limited to 'prism_compile.c')
-rw-r--r--prism_compile.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 79d5267667..58a6c0402f 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -1663,9 +1663,15 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
// is popped, then we know we don't need to do anything since it's
// statically known.
if (!popped) {
- VALUE value = pm_static_literal_value(node, scope_node, parser);
- ADD_INSN1(ret, &dummy_line_node, duparray, value);
- RB_OBJ_WRITTEN(iseq, Qundef, value);
+ pm_array_node_t *cast = (pm_array_node_t *) node;
+ if (cast->elements.size) {
+ VALUE value = pm_static_literal_value(node, scope_node, parser);
+ ADD_INSN1(ret, &dummy_line_node, duparray, value);
+ RB_OBJ_WRITTEN(iseq, Qundef, value);
+ }
+ else {
+ ADD_INSN1(ret, &dummy_line_node, newarray, INT2FIX(0));
+ }
}
} else {
// Here since we know there are possible side-effects inside the