mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
hash.c: use rb_hash_new_with_size()
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
327b22ad77
commit
8efc41329d
1 changed files with 6 additions and 5 deletions
11
array.c
11
array.c
|
@ -2180,7 +2180,7 @@ static VALUE
|
||||||
rb_ary_to_h(VALUE ary)
|
rb_ary_to_h(VALUE ary)
|
||||||
{
|
{
|
||||||
long i;
|
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++) {
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||||
const VALUE elt = rb_ary_elt(ary, i);
|
const VALUE elt = rb_ary_elt(ary, i);
|
||||||
const VALUE key_value_pair = rb_check_array_type(elt);
|
const VALUE key_value_pair = rb_check_array_type(elt);
|
||||||
|
@ -4081,9 +4081,10 @@ ary_add_hash(VALUE hash, VALUE ary)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline VALUE
|
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);
|
RBASIC_CLEAR_CLASS(hash);
|
||||||
return hash;
|
return hash;
|
||||||
|
@ -4092,7 +4093,7 @@ ary_tmp_hash_new(void)
|
||||||
static VALUE
|
static VALUE
|
||||||
ary_make_hash(VALUE ary)
|
ary_make_hash(VALUE ary)
|
||||||
{
|
{
|
||||||
VALUE hash = ary_tmp_hash_new();
|
VALUE hash = ary_tmp_hash_new(ary);
|
||||||
return ary_add_hash(hash, ary);
|
return ary_add_hash(hash, ary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4111,7 +4112,7 @@ ary_add_hash_by(VALUE hash, VALUE ary)
|
||||||
static VALUE
|
static VALUE
|
||||||
ary_make_hash_by(VALUE ary)
|
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);
|
return ary_add_hash_by(hash, ary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue