Optimize non-array iteration of _.max and _.min when no iterator is provided.

This commit is contained in:
John-David Dalton
2014-07-14 00:49:52 -07:00
parent 381ecd8f70
commit 37caef10b1

View File

@@ -4975,18 +4975,23 @@
if ((type == 'number' || type == 'string') && thisArg && thisArg[iterator] === collection) { if ((type == 'number' || type == 'string') && thisArg && thisArg[iterator] === collection) {
iterator = null; iterator = null;
} }
if (iterator == null && isArray(collection)) { var noIterator = iterator == null,
isArr = noIterator && isArray(collection),
isStr = !isArr && isString(collection);
if (noIterator && !isStr) {
var index = -1, var index = -1,
length = collection.length; iterable = isArr ? collection : values(collection),
length = iterable.length;
while (++index < length) { while (++index < length) {
var value = collection[index]; var value = iterable[index];
if (value > result) { if (value > result) {
result = value; result = value;
} }
} }
} else { } else {
iterator = (iterator == null && isString(collection)) iterator = (noIterator && isStr)
? charAtCallback ? charAtCallback
: getCallback(iterator, thisArg, 3); : getCallback(iterator, thisArg, 3);
@@ -5053,18 +5058,23 @@
if ((type == 'number' || type == 'string') && thisArg && thisArg[iterator] === collection) { if ((type == 'number' || type == 'string') && thisArg && thisArg[iterator] === collection) {
iterator = null; iterator = null;
} }
if (iterator == null && isArray(collection)) { var noIterator = iterator == null,
isArr = noIterator && isArray(collection),
isStr = !isArr && isString(collection);
if (noIterator && !isStr) {
var index = -1, var index = -1,
length = collection.length; iterable = isArr ? collection : values(collection),
length = iterable.length;
while (++index < length) { while (++index < length) {
var value = collection[index]; var value = iterable[index];
if (value < result) { if (value < result) {
result = value; result = value;
} }
} }
} else { } else {
iterator = (iterator == null && isString(collection)) iterator = (noIterator && isStr)
? charAtCallback ? charAtCallback
: getCallback(iterator, thisArg, 3); : getCallback(iterator, thisArg, 3);