mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57: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) {
|
||||
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,
|
||||
length = collection.length;
|
||||
iterable = isArr ? collection : values(collection),
|
||||
length = iterable.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
var value = iterable[index];
|
||||
if (value > result) {
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
iterator = (iterator == null && isString(collection))
|
||||
iterator = (noIterator && isStr)
|
||||
? charAtCallback
|
||||
: getCallback(iterator, thisArg, 3);
|
||||
|
||||
@@ -5053,18 +5058,23 @@
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[iterator] === collection) {
|
||||
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,
|
||||
length = collection.length;
|
||||
iterable = isArr ? collection : values(collection),
|
||||
length = iterable.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
var value = iterable[index];
|
||||
if (value < result) {
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
iterator = (iterator == null && isString(collection))
|
||||
iterator = (noIterator && isStr)
|
||||
? charAtCallback
|
||||
: getCallback(iterator, thisArg, 3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user