mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
array.c: Mem optim for Array#select
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
de6c650f44
commit
f34a26bf90
1 changed files with 3 additions and 1 deletions
4
array.c
4
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])));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue