Avoid inspecting the entire key-value array when adding values to a stack.

This commit is contained in:
John-David Dalton
2016-05-24 09:43:00 -07:00
parent e18b577d20
commit 98c422d227

View File

@@ -2122,8 +2122,13 @@
*/
function stackSet(key, value) {
var cache = this.__data__;
if (Map && cache instanceof ListCache && cache.__data__.length == LARGE_ARRAY_SIZE) {
cache = this.__data__ = new MapCache(cache.__data__);
if (cache instanceof ListCache) {
var pairs = cache.__data__;
if (!Map || pairs.length < LARGE_ARRAY_SIZE) {
pairs.push([key, value]);
return this;
}
cache = this.__data__ = new MapCache(pairs);
}
cache.set(key, value);
return this;