From 5e11de658511efd346ed8bb0fac8a49e7c0eb963 Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 3 Dec 2018 12:36:39 +0000 Subject: make `RARRAY_PTR_USE` more conservertive. * include/ruby/ruby.h: de-transient at `RARRAY_PTR_USE` and `RARRAY_PTR_USE_START`. Introduce `RARRAY_PTR_USE_TRANSIENT` and `RARRAY_PTR_USE_START_TRANSIENT` if you don't want to de-transient an array. Generally, it is difficult so C-extension writers should not use them. * array.c: use `RARRAY_PTR_USE_TRANSIENT` if possible. * hash.c: ditto. * enum.c (enum_sort_by): remove `rb_ary_transient_heap_evacuate()` because `RARRAY_PTR_USE` do de-transient. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index ad9f495192..6bd59eb45c 100644 --- a/hash.c +++ b/hash.c @@ -3113,27 +3113,22 @@ keys_i(VALUE key, VALUE value, VALUE ary) MJIT_FUNC_EXPORTED VALUE rb_hash_keys(VALUE hash) { - VALUE keys; st_index_t size = RHASH_SIZE(hash); + VALUE keys = rb_ary_new_capa(size); - keys = rb_ary_new_capa(size); if (size == 0) return keys; if (ST_DATA_COMPATIBLE_P(VALUE)) { - if (RHASH_ARRAY_P(hash)) { - rb_gc_writebarrier_remember(keys); - RARRAY_PTR_USE(keys, ptr, { + RARRAY_PTR_USE_TRANSIENT(keys, ptr, { + if (RHASH_ARRAY_P(hash)) { size = linear_keys(hash, ptr, size); - }); - } - else if (RHASH_TABLE_P(hash)) { - st_table *table = RHASH_ST_TABLE(hash); - - rb_gc_writebarrier_remember(keys); - RARRAY_PTR_USE(keys, ptr, { - size = st_keys(table, ptr, size); - }); - } + } + else { + st_table *table = RHASH_ST_TABLE(hash); + size = st_keys(table, ptr, size); + } + }); + rb_gc_writebarrier_remember(keys); rb_ary_set_len(keys, size); } else { @@ -3174,15 +3169,14 @@ rb_hash_values(VALUE hash) if (ST_DATA_COMPATIBLE_P(VALUE)) { if (RHASH_ARRAY_P(hash)) { rb_gc_writebarrier_remember(values); - RARRAY_PTR_USE(values, ptr, { + RARRAY_PTR_USE_TRANSIENT(values, ptr, { size = linear_values(hash, ptr, size); }); } else if (RHASH_TABLE_P(hash)) { st_table *table = RHASH_ST_TABLE(hash); - rb_gc_writebarrier_remember(values); - RARRAY_PTR_USE(values, ptr, { + RARRAY_PTR_USE_TRANSIENT(values, ptr, { size = st_values(table, ptr, size); }); } -- cgit v1.2.3