mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 21:49:06 +02:00
array.c: reduce to_ary call
* array.c (flatten): no need to call to_ary method on elements beyond the given level. [ruby-core:67637] [Bug #10748] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7d87d0c466
commit
aa436bdca6
4 changed files with 39 additions and 1 deletions
6
array.c
6
array.c
|
@ -4387,11 +4387,15 @@ flatten(VALUE ary, int level, int *modified)
|
|||
while (1) {
|
||||
while (i < RARRAY_LEN(ary)) {
|
||||
elt = RARRAY_AREF(ary, i++);
|
||||
if (level >= 0 && RARRAY_LEN(stack) / 2 >= level) {
|
||||
rb_ary_push(result, elt);
|
||||
continue;
|
||||
}
|
||||
tmp = rb_check_array_type(elt);
|
||||
if (RBASIC(result)->klass) {
|
||||
rb_raise(rb_eRuntimeError, "flatten reentered");
|
||||
}
|
||||
if (NIL_P(tmp) || (level >= 0 && RARRAY_LEN(stack) / 2 >= level)) {
|
||||
if (NIL_P(tmp)) {
|
||||
rb_ary_push(result, elt);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue