summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-07-19 11:15:05 -0400
committerPeter Zhu <peter@peterzhu.ca>2022-07-20 13:13:56 -0400
commit5871ecf956711fcacad7c03f2aef95115ed25bc4 (patch)
treeef8db409dd1acd1d2184279d8a8d3893f6b965f6 /compile.c
parentb25ee69e3873162689c46bc3ffdd1686151184b2 (diff)
Add RARRAY_LITERAL_FLAG for array literals
Array created as literals during iseq compilation don't need a reference count since they can never be modified. The previous implementation would mutate the hidden array's reference count, causing copy-on-write invalidation. This commit adds a RARRAY_LITERAL_FLAG for arrays created through rb_ary_literal_new. Arrays created with this flag do not have reference count stored and just assume they have infinite number of references. Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6151
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index f95b3bb143..8c975782d7 100644
--- a/compile.c
+++ b/compile.c
@@ -4369,7 +4369,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int pop
if ((first_chunk && stack_len == 0 && !node_tmp) || count >= min_tmp_ary_len) {
/* The literal contains only optimizable elements, or the subarray is long enough */
- VALUE ary = rb_ary_tmp_new(count);
+ VALUE ary = rb_ary_literal_new(count);
/* Create a hidden array */
for (; count; count--, node = node->nd_next)
@@ -12349,7 +12349,7 @@ ibf_load_object_array(const struct ibf_load *load, const struct ibf_object_heade
const long len = (long)ibf_load_small_value(load, &reading_pos);
- VALUE ary = rb_ary_new_capa(len);
+ VALUE ary = header->internal ? rb_ary_literal_new(len) : rb_ary_new_capa(len);
int i;
for (i=0; i<len; i++) {