aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-10 02:25:33 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-10 02:25:33 +0000
commitd90818016436a069590277c5fb07a4f50c2feb87 (patch)
treea8e8970dc2b473198d39ca1d978e1803077250ac /enum.c
parent2ce35ac8636f76c09dcb1f5d56e050ca92409c14 (diff)
downloadruby-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.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/enum.c b/enum.c
index a49e4b0b74..ea151b464d 100644
--- a/enum.c
+++ b/enum.c
@@ -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);