aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-29 20:39:51 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-29 20:39:51 +0000
commitd46cd60f3cfb88f1591d6ce0f23e750d3833434f (patch)
tree0a2b5954b54a701c3576ef6e65cf98e6c6df6609 /array.c
parent0620c97e02d2581334819f4ba1906fed9b09a361 (diff)
downloadruby-d46cd60f3cfb88f1591d6ce0f23e750d3833434f.tar.gz
Use a shared array for the `duparray` instruction
In this example code: ```ruby def foo [1, 2, 3, 4] end ``` The array literal uses a `duparray` instruction. Before this patch, `rb_ary_resurrect` would malloc and memcpy a new array buffer. This patch changes `rb_ary_resurrect` to use `ary_make_partial` so that the new array object shares the underlying buffer with the array stored in the instruction sequences. Before this patch, the new array object is not shared: ``` $ ruby -r objspace -e'p ObjectSpace.dump([1, 2, 3, 4])' "{\"address\":\"0x7fa2718372d0\", \"type\":\"ARRAY\", \"class\":\"0x7fa26f8b0010\", \"length\":4, \"memsize\":72, \"flags\":{\"wb_protected\":true}}\n" ``` After this patch: ``` $ ./ruby -r objspace -e'p ObjectSpace.dump([1, 2, 3, 4])' "{\"address\":\"0x7f9a76883638\", \"type\":\"ARRAY\", \"class\":\"0x7f9a758af900\", \"length\":4, \"shared\":true, \"references\":[\"0x7f9a768837c8\"], \"memsize\":40, \"flags\":{\"wb_protected\":true}}\n" ``` [Feature #15289] [ruby-core:90097] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/array.c b/array.c
index f74ceab04e..38ed1753bd 100644
--- a/array.c
+++ b/array.c
@@ -2191,7 +2191,7 @@ rb_ary_dup(VALUE ary)
VALUE
rb_ary_resurrect(VALUE ary)
{
- return rb_ary_new4(RARRAY_LEN(ary), RARRAY_CONST_PTR_TRANSIENT(ary));
+ return ary_make_partial(ary, rb_cArray, 0, RARRAY_LEN(ary));
}
extern VALUE rb_output_fs;