From 7268ff1ac82ee70293478f45204c0446f29c1209 Mon Sep 17 00:00:00 2001 From: glass Date: Sun, 1 Oct 2017 04:26:25 +0000 Subject: use rb_hash_new_with_size() * hash.c: use rb_hash_new_with_size(). * marshal.c: ditto * struct.c: ditto * vm_args.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 2 +- marshal.c | 2 +- struct.c | 2 +- vm_args.c | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hash.c b/hash.c index b666fd156f..878e215dc5 100644 --- a/hash.c +++ b/hash.c @@ -2426,7 +2426,7 @@ rb_hash_invert_i(VALUE key, VALUE value, VALUE hash) static VALUE rb_hash_invert(VALUE hash) { - VALUE h = rb_hash_new(); + VALUE h = rb_hash_new_with_size(RHASH_SIZE(hash)); rb_hash_foreach(hash, rb_hash_invert_i, h); return h; diff --git a/marshal.c b/marshal.c index 7e16d0b024..61eb01e721 100644 --- a/marshal.c +++ b/marshal.c @@ -1772,7 +1772,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod) { long len = r_long(arg); - v = rb_hash_new(); + v = rb_hash_new_with_size(len); v = r_entry(v, arg); arg->readable += (len - 1) * 2; while (len--) { diff --git a/struct.c b/struct.c index f1f361f953..b36dd37e4b 100644 --- a/struct.c +++ b/struct.c @@ -794,7 +794,7 @@ rb_struct_to_a(VALUE s) static VALUE rb_struct_to_h(VALUE s) { - VALUE h = rb_hash_new(); + VALUE h = rb_hash_new_with_size(RSTRUCT_LEN(s)); VALUE members = rb_struct_members(s); long i; diff --git a/vm_args.c b/vm_args.c index 39f511998d..19eae944d0 100644 --- a/vm_args.c +++ b/vm_args.c @@ -239,7 +239,7 @@ args_kw_argv_to_hash(struct args_info *args) const struct rb_call_info_kw_arg *kw_arg = args->kw_arg; const VALUE *const passed_keywords = kw_arg->keywords; const int kw_len = kw_arg->keyword_len; - VALUE h = rb_hash_new(); + VALUE h = rb_hash_new_with_size(kw_len); const int kw_start = args->argc - kw_len; const VALUE * const kw_argv = args->argv + kw_start; int i; @@ -257,11 +257,11 @@ args_kw_argv_to_hash(struct args_info *args) static void args_stored_kw_argv_to_hash(struct args_info *args) { - VALUE h = rb_hash_new(); int i; const struct rb_call_info_kw_arg *kw_arg = args->kw_arg; const VALUE *const passed_keywords = kw_arg->keywords; const int passed_keyword_len = kw_arg->keyword_len; + VALUE h = rb_hash_new_with_size(passed_keyword_len); for (i=0; ikw_argv[i]); @@ -365,7 +365,7 @@ static VALUE make_rest_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv) { int i; - VALUE obj = rb_hash_new(); + VALUE obj = rb_hash_new_with_size(passed_keyword_len); for (i=0; ikw_arg->keywords; const int kw_len = ci_kw->kw_arg->keyword_len; - const VALUE h = rb_hash_new(); + const VALUE h = rb_hash_new_with_size(kw_len); VALUE *sp = cfp->sp; int i; -- cgit v1.2.3