ruby-changes:47970
From: glass <ko1@a...>
Date: Sun, 1 Oct 2017 13:26:29 +0900 (JST)
Subject: [ruby-changes:47970] glass:r60085 (trunk): use rb_hash_new_with_size()
glass 2017-10-01 13:26:25 +0900 (Sun, 01 Oct 2017) New Revision: 60085 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60085 Log: use rb_hash_new_with_size() * hash.c: use rb_hash_new_with_size(). * marshal.c: ditto * struct.c: ditto * vm_args.c: ditto Modified files: trunk/hash.c trunk/marshal.c trunk/struct.c trunk/vm_args.c Index: marshal.c =================================================================== --- marshal.c (revision 60084) +++ marshal.c (revision 60085) @@ -1772,7 +1772,7 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/marshal.c#L1772 { 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--) { Index: vm_args.c =================================================================== --- vm_args.c (revision 60084) +++ vm_args.c (revision 60085) @@ -239,7 +239,7 @@ args_kw_argv_to_hash(struct args_info *a https://github.com/ruby/ruby/blob/trunk/vm_args.c#L239 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 *a https://github.com/ruby/ruby/blob/trunk/vm_args.c#L257 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; i<passed_keyword_len; i++) { rb_hash_aset(h, passed_keywords[i], args->kw_argv[i]); @@ -365,7 +365,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/vm_args.c#L365 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; i<passed_keyword_len; i++) { if (kw_argv[i] != Qundef) { @@ -780,7 +780,7 @@ vm_caller_setup_arg_kw(rb_control_frame_ https://github.com/ruby/ruby/blob/trunk/vm_args.c#L780 struct rb_call_info_with_kwarg *ci_kw = (struct rb_call_info_with_kwarg *)ci; const VALUE *const passed_keywords = ci_kw->kw_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; Index: hash.c =================================================================== --- hash.c (revision 60084) +++ hash.c (revision 60085) @@ -2426,7 +2426,7 @@ rb_hash_invert_i(VALUE key, VALUE value, https://github.com/ruby/ruby/blob/trunk/hash.c#L2426 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; Index: struct.c =================================================================== --- struct.c (revision 60084) +++ struct.c (revision 60085) @@ -794,7 +794,7 @@ rb_struct_to_a(VALUE s) https://github.com/ruby/ruby/blob/trunk/struct.c#L794 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/