summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-05 04:48:19 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-05 04:48:19 +0000
commit0eb7359cc775c9d4c8dad68dd9dbf38c9680071e (patch)
treea4e596d906225086566efe79e792a3f204a16b57 /vm.c
parente5684558262ead5253b9fce36efaea6a6ae6acab (diff)
add rb_hash_new_with_size()
Sometimes, size of a hash can be calcluated a priori. By providing such info to the constructor we can avoid unnecessary internal re- allocations. This can boost for instance creation of hash literals. [Bug #13861] Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/vm.c b/vm.c
index 1da03c4566..0bf3707f3a 100644
--- a/vm.c
+++ b/vm.c
@@ -2694,7 +2694,7 @@ m_core_hash_from_ary(VALUE self, VALUE ary)
static VALUE
core_hash_from_ary(VALUE ary)
{
- VALUE hash = rb_hash_new();
+ VALUE hash = rb_hash_new_with_size(RARRAY_LEN(ary) / 2);
RUBY_DTRACE_CREATE_HOOK(HASH, (Check_Type(ary, T_ARRAY), RARRAY_LEN(ary)));
return core_hash_merge_ary(hash, ary);