summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-03 12:36:39 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-03 12:36:39 +0000
commit5e11de658511efd346ed8bb0fac8a49e7c0eb963 (patch)
tree2e62e61d46462125ce7c2712a0cb6f0acbea30ba /hash.c
parent60989daa1b1960468933a2ab85352d95829c329e (diff)
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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c30
1 files changed, 12 insertions, 18 deletions
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);
});
}