mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Optimize non-array iteration of _.max and _.min when no iterator is provided.
This commit is contained in:
26
lodash.js
26
lodash.js
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user