Ensure _.flatten works with extremely large arrays. [closes #349]

This commit is contained in:
John-David Dalton
2013-09-15 18:37:09 -07:00
parent 9f1f2a4845
commit 3dc8436362
8 changed files with 123 additions and 71 deletions

View File

@@ -420,7 +420,17 @@
var value = array[index];
// recursively flatten arrays (susceptible to call stack limits)
if (value && typeof value == 'object' && (isArray(value) || isArguments(value))) {
push.apply(result, isShallow ? value : baseFlatten(value, isShallow, isArgArrays));
if (!isShallow) {
value = baseFlatten(value, isShallow, isArgArrays);
}
var pad = result.length,
valIndex = -1,
valLength = value.length;
result.length += valLength;
while (++valIndex < valLength) {
result[pad + valIndex] = value[valIndex];
}
} else if (!isArgArrays) {
result.push(value);
}