ruby-changes:47987
From: nobu <ko1@a...>
Date: Mon, 2 Oct 2017 21:23:23 +0900 (JST)
Subject: [ruby-changes:47987] nobu:r60101 (trunk): use rb_hash_new_with_size()
nobu 2017-10-02 21:23:17 +0900 (Mon, 02 Oct 2017) New Revision: 60101 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60101 Log: use rb_hash_new_with_size() Modified files: trunk/compile.c trunk/gc.c trunk/re.c Index: gc.c =================================================================== --- gc.c (revision 60100) +++ gc.c (revision 60101) @@ -6735,7 +6735,7 @@ static const char *type_name(int type, V https://github.com/ruby/ruby/blob/trunk/gc.c#L6735 static void gc_count_add_each_types(VALUE hash, const char *name, const size_t *types) { - VALUE result = rb_hash_new(); + VALUE result = rb_hash_new_with_size(T_MASK); int i; for (i=0; i<T_MASK; i++) { const char *type = type_name(i, 0); Index: compile.c =================================================================== --- compile.c (revision 60100) +++ compile.c (revision 60101) @@ -7203,7 +7203,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/compile.c#L7203 case TS_CDHASH: { int i; - VALUE map = rb_hash_new(); + VALUE map = rb_hash_new_with_size(RARRAY_LEN(op)/2); rb_hash_tbl_raw(map)->type = &cdhash_type; op = rb_convert_type_with_id(op, T_ARRAY, "Array", idTo_ary); @@ -8525,7 +8525,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/compile.c#L8525 ibf_load_object_hash(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset) { const struct ibf_object_hash *hash = IBF_OBJBODY(struct ibf_object_hash, offset); - VALUE obj = rb_hash_new(); + VALUE obj = rb_hash_new_with_size(hash->len); int i; for (i=0; i<hash->len; i++) { Index: re.c =================================================================== --- re.c (revision 60100) +++ re.c (revision 60101) @@ -820,9 +820,9 @@ reg_named_captures_iter(const OnigUChar https://github.com/ruby/ruby/blob/trunk/re.c#L820 static VALUE rb_reg_named_captures(VALUE re) { - VALUE hash = rb_hash_new(); - rb_reg_check(re); - onig_foreach_name(RREGEXP_PTR(re), reg_named_captures_iter, (void*)hash); + regex_t *reg = (rb_reg_check(re), RREGEXP_PTR(re)); + VALUE hash = rb_hash_new_with_size(onig_number_of_names(reg)); + onig_foreach_name(reg, reg_named_captures_iter, (void*)hash); return hash; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/