Skip to content

Commit

Permalink
Check the whole result only on different length in Array#flatten!
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Oct 24, 2013
1 parent 5aa9af2 commit 6a62d0b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions corelib/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,16 @@ def flatten!(level = undefined)
%x{
var flattened = #{flatten level};
for (var i = 0, length = self.length; i < length; i++) {
if (self[i] !== flattened[i]) {
break;
if (self.length == flattened.length) {
for (var i = 0, length = self.length; i < length; i++) {
if (self[i] !== flattened[i]) {
break;
}
}
}
if (i == length) {
return nil;
if (i == length) {
return nil;
}
}
#{replace `flattened`};
Expand Down

0 comments on commit 6a62d0b

Please sign in to comment.