diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-10 02:25:33 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-10 02:25:33 +0000 |
commit | d90818016436a069590277c5fb07a4f50c2feb87 (patch) | |
tree | a8e8970dc2b473198d39ca1d978e1803077250ac /enum.c | |
parent | 2ce35ac8636f76c09dcb1f5d56e050ca92409c14 (diff) | |
download | ruby-d90818016436a069590277c5fb07a4f50c2feb87.tar.gz |
* enum.c (enum_to_a): Use size to set array capa when possible.
the patch is from HonoreDB <aweiner at mdsol.com>.
[fix GH-444]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -515,7 +515,14 @@ enum_flat_map(VALUE obj) static VALUE enum_to_a(int argc, VALUE *argv, VALUE obj) { - VALUE ary = rb_ary_new(); + VALUE ary, size = rb_check_funcall(obj, id_size, 0, 0); + + if (NIL_P(size) || size == Qundef) { + ary = rb_ary_new(); + } + else { + ary = rb_ary_new_capa(NUM2LONG(size)); + } rb_block_call(obj, id_each, argc, argv, collect_all, ary); OBJ_INFECT(ary, obj); |