mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Adjust lazy eval heuristic.
This commit is contained in:
@@ -1162,22 +1162,25 @@
|
|||||||
* @returns {*} Returns the unwrapped value.
|
* @returns {*} Returns the unwrapped value.
|
||||||
*/
|
*/
|
||||||
function lazyValue() {
|
function lazyValue() {
|
||||||
var array = this.__wrapped__.value();
|
var array = this.__wrapped__.value(),
|
||||||
if (!isArray(array)) {
|
dir = this.__dir__,
|
||||||
return baseWrapperValue(array, this.__actions__);
|
isArr = isArray(array),
|
||||||
}
|
|
||||||
var dir = this.__dir__,
|
|
||||||
isRight = dir < 0,
|
isRight = dir < 0,
|
||||||
view = getView(0, array.length, this.__views__),
|
arrLength = isArr ? array.length : 0,
|
||||||
|
view = getView(0, arrLength, this.__views__),
|
||||||
start = view.start,
|
start = view.start,
|
||||||
end = view.end,
|
end = view.end,
|
||||||
length = end - start,
|
length = end - start,
|
||||||
index = isRight ? end : (start - 1),
|
index = isRight ? end : (start - 1),
|
||||||
takeCount = nativeMin(length, this.__takeCount__),
|
|
||||||
iteratees = this.__iteratees__,
|
iteratees = this.__iteratees__,
|
||||||
iterLength = iteratees.length,
|
iterLength = iteratees.length,
|
||||||
resIndex = 0,
|
resIndex = 0,
|
||||||
result = [];
|
takeCount = nativeMin(length, this.__takeCount__);
|
||||||
|
|
||||||
|
if (!isArr || (iterLength < 2 && arrLength == length && takeCount == length)) {
|
||||||
|
return baseWrapperValue(isRight ? array.reverse() : array, this.__actions__);
|
||||||
|
}
|
||||||
|
var result = [];
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
while (length-- && resIndex < takeCount) {
|
while (length-- && resIndex < takeCount) {
|
||||||
@@ -3419,12 +3422,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return function() {
|
return function() {
|
||||||
var args = arguments;
|
var args = arguments,
|
||||||
if (wrapper && args.length == 1 && isArray(args[0])) {
|
value = args[0];
|
||||||
return wrapper.plant(args[0]).value();
|
|
||||||
|
if (wrapper && args.length == 1 && isArray(value)) {
|
||||||
|
return wrapper.plant(value).value();
|
||||||
}
|
}
|
||||||
var index = 0,
|
var index = 0,
|
||||||
result = length ? funcs[index].apply(this, args) : args[0];
|
result = length ? funcs[index].apply(this, args) : value;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
result = funcs[index].call(this, result);
|
result = funcs[index].call(this, result);
|
||||||
@@ -6167,15 +6172,16 @@
|
|||||||
var value = this.__wrapped__;
|
var value = this.__wrapped__;
|
||||||
|
|
||||||
var interceptor = function(value) {
|
var interceptor = function(value) {
|
||||||
return value.reverse();
|
return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse();
|
||||||
};
|
};
|
||||||
if (value instanceof LazyWrapper) {
|
if (value instanceof LazyWrapper) {
|
||||||
|
var wrapped = value;
|
||||||
if (this.__actions__.length) {
|
if (this.__actions__.length) {
|
||||||
value = new LazyWrapper(this);
|
wrapped = new LazyWrapper(this);
|
||||||
}
|
}
|
||||||
value = value.reverse();
|
wrapped = wrapped.reverse();
|
||||||
value.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
|
wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
|
||||||
return new LodashWrapper(value, this.__chain__);
|
return new LodashWrapper(wrapped, this.__chain__);
|
||||||
}
|
}
|
||||||
return this.thru(interceptor);
|
return this.thru(interceptor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2240,7 +2240,7 @@
|
|||||||
: fn(take2, _.compact, filter2, map2);
|
: fn(take2, _.compact, filter2, map2);
|
||||||
|
|
||||||
filterCount = mapCount = 0;
|
filterCount = mapCount = 0;
|
||||||
deepEqual(combined(_.range(100)), [4, 16]);
|
deepEqual(combined(_.range(200)), [4, 16]);
|
||||||
|
|
||||||
if (!isNpm && WeakMap && WeakMap.name) {
|
if (!isNpm && WeakMap && WeakMap.name) {
|
||||||
strictEqual(filterCount, 5, 'filterCount');
|
strictEqual(filterCount, 5, 'filterCount');
|
||||||
@@ -4050,7 +4050,7 @@
|
|||||||
args = slice.call(arguments);
|
args = slice.call(arguments);
|
||||||
}).value();
|
}).value();
|
||||||
|
|
||||||
deepEqual(args, [16]);
|
deepEqual(args, expected);
|
||||||
|
|
||||||
_(array).map(square).dropRightWhile(function() {
|
_(array).map(square).dropRightWhile(function() {
|
||||||
args = slice.call(arguments);
|
args = slice.call(arguments);
|
||||||
|
|||||||
Reference in New Issue
Block a user