[前][次][番号順一覧][スレッド一覧]

ruby-changes:47963

From: glass <ko1@a...>
Date: Sat, 30 Sep 2017 22:14:15 +0900 (JST)
Subject: [ruby-changes:47963] glass:r60078 (trunk): hash.c: use rb_hash_new_with_size()

glass	2017-09-30 22:14:09 +0900 (Sat, 30 Sep 2017)

  New Revision: 60078

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60078

  Log:
    hash.c: use rb_hash_new_with_size()

  Modified files:
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 60077)
+++ array.c	(revision 60078)
@@ -2180,7 +2180,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/array.c#L2180
 rb_ary_to_h(VALUE ary)
 {
     long i;
-    VALUE hash = rb_hash_new();
+    VALUE hash = rb_hash_new_with_size(RARRAY_LEN(ary));
     for (i=0; i<RARRAY_LEN(ary); i++) {
 	const VALUE elt = rb_ary_elt(ary, i);
 	const VALUE key_value_pair = rb_check_array_type(elt);
@@ -4081,9 +4081,10 @@ ary_add_hash(VALUE hash, VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L4081
 }
 
 static inline VALUE
-ary_tmp_hash_new(void)
+ary_tmp_hash_new(VALUE ary)
 {
-    VALUE hash = rb_hash_new();
+    long size = RARRAY_LEN(ary);
+    VALUE hash = rb_hash_new_with_size(size);
 
     RBASIC_CLEAR_CLASS(hash);
     return hash;
@@ -4092,7 +4093,7 @@ ary_tmp_hash_new(void) https://github.com/ruby/ruby/blob/trunk/array.c#L4093
 static VALUE
 ary_make_hash(VALUE ary)
 {
-    VALUE hash = ary_tmp_hash_new();
+    VALUE hash = ary_tmp_hash_new(ary);
     return ary_add_hash(hash, ary);
 }
 
@@ -4111,7 +4112,7 @@ ary_add_hash_by(VALUE hash, VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L4112
 static VALUE
 ary_make_hash_by(VALUE ary)
 {
-    VALUE hash = ary_tmp_hash_new();
+    VALUE hash = ary_tmp_hash_new(ary);
     return ary_add_hash_by(hash, ary);
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]