From 98c422d227fb9110cc4971f545c7d0e96dc66c03 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 24 May 2016 09:43:00 -0700 Subject: [PATCH] Avoid inspecting the entire key-value array when adding values to a stack. --- lodash.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index ed59da8ba..fb68399b2 100644 --- a/lodash.js +++ b/lodash.js @@ -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;