Disable lazy optimizations if the iteratee has more than one param. [closes #997]

This commit is contained in:
jdalton
2015-02-26 00:58:27 -08:00
parent 9f213c119c
commit 6bb3b9a684
2 changed files with 195 additions and 39 deletions

View File

@@ -11484,7 +11484,7 @@
iteratees = result.__iteratees__ || (result.__iteratees__ = []);
result.__filtered__ = result.__filtered__ || isFilter;
iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index });
iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': index });
return result;
};
});
@@ -11554,7 +11554,7 @@
lastIndex,
isRight = this.__dir__ < 0;
predicate = getCallback(predicate, thisArg, 3);
predicate = getCallback(predicate, thisArg, 1);
return this.filter(function(value, index, array) {
done = done && (isRight ? index < lastIndex : index > lastIndex);
lastIndex = index;
@@ -11563,7 +11563,7 @@
};
LazyWrapper.prototype.reject = function(predicate, thisArg) {
predicate = getCallback(predicate, thisArg, 3);
predicate = getCallback(predicate, thisArg, 1);
return this.filter(function(value, index, array) {
return !predicate(value, index, array);
});
@@ -11587,6 +11587,7 @@
// Add `LazyWrapper` methods to `lodash.prototype`.
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var lodashFunc = lodash[methodName],
checkIteratee = /(?:filter|map|reject|While)/.test(methodName),
retUnwrapped = /^(?:first|last)$/.test(methodName);
lodash.prototype[methodName] = function() {
@@ -11594,9 +11595,14 @@
args = arguments,
chainAll = this.__chain__,
isHybrid = !!this.__actions__.length,
isLazy = value instanceof LazyWrapper,
onlyLazy = isLazy && !isHybrid;
isLazy = value instanceof LazyWrapper;
if (isLazy && checkIteratee) {
// avoid lazy use if the iteratee has a `length` other than `1`
var iteratee = args[0];
isLazy = !(typeof iteratee == 'function' && iteratee.length != 1);
}
var onlyLazy = isLazy && !isHybrid;
if (retUnwrapped && !chainAll) {
return onlyLazy
? func.call(value)