ruby-changes:65671
From: Nobuyoshi <ko1@a...>
Date: Sun, 28 Mar 2021 09:48:57 +0900 (JST)
Subject: [ruby-changes:65671] fb6ebe55d9 (master): Hide an intermediate array
https://git.ruby-lang.org/ruby.git/commit/?id=fb6ebe55d9 From fb6ebe55d91187d9635e0183d47dbf38e95b1141 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 28 Mar 2021 09:48:45 +0900 Subject: Hide an intermediate array --- hash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hash.c b/hash.c index 00beadf..17864a0 100644 --- a/hash.c +++ b/hash.c @@ -3239,7 +3239,7 @@ rb_hash_transform_keys(int argc, VALUE *argv, VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3239 return result; } -static VALUE rb_hash_flatten(int argc, VALUE *argv, VALUE hash); +static int flatten_i(VALUE key, VALUE val, VALUE ary); /* * call-seq: @@ -3269,7 +3269,8 @@ rb_hash_transform_keys_bang(int argc, VALUE *argv, VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3269 if (!RHASH_TABLE_EMPTY_P(hash)) { long i; VALUE new_keys = hash_alloc(0); - VALUE pairs = rb_hash_flatten(0, NULL, hash); + VALUE pairs = rb_ary_tmp_new(RHASH_SIZE(hash) * 2); + rb_hash_foreach(hash, flatten_i, pairs); for (i = 0; i < RARRAY_LEN(pairs); i += 2) { VALUE key = RARRAY_AREF(pairs, i), new_key, val; @@ -3292,6 +3293,7 @@ rb_hash_transform_keys_bang(int argc, VALUE *argv, VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3293 rb_hash_aset(hash, new_key, val); rb_hash_aset(new_keys, new_key, Qnil); } + rb_ary_clear(pairs); rb_hash_clear(new_keys); } return hash; -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/