summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormichal <michal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-23 15:04:27 +0000
committermichal <michal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-23 15:04:27 +0000
commitf34a26bf9036a385abd0922bb4c3cc61be6991bf (patch)
tree6665c7e1bb66044f79e73adf8de2036806eb80dd /array.c
parentde6c650f442ead03b7b4485b07f719a35e67524b (diff)
array.c: Mem optim for Array#select
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/array.c b/array.c
index 85258e9..39ae90c 100644
--- a/array.c
+++ b/array.c
@@ -1180,13 +1180,14 @@ rb_ary_select(argc, argv, ary)
VALUE *argv;
VALUE ary;
{
- VALUE result = rb_ary_new();
+ VALUE result;
long i;
if (rb_block_given_p()) {
if (argc > 0) {
rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
}
+ result = rb_ary_new2(RARRAY(ary)->len);
for (i = 0; i < RARRAY(ary)->len; i++) {
if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
rb_ary_push(result, RARRAY(ary)->ptr[i]);
@@ -1194,6 +1195,7 @@ rb_ary_select(argc, argv, ary)
}
}
else {
+ result = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(argv[i])));
}