From dfd865dadc35242840340dbca082a49223e0e810 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 27 Feb 2016 20:44:19 -0800 Subject: [PATCH] Only use `SetCache` in `baseIntersection` only when `arrays[0]` is large. --- lodash.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index b824f901b..b3f3c2772 100644 --- a/lodash.js +++ b/lodash.js @@ -2766,6 +2766,7 @@ */ function baseIntersection(arrays, iteratee, comparator) { var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, othLength = arrays.length, othIndex = othLength, caches = Array(othLength), @@ -2777,14 +2778,12 @@ if (othIndex && iteratee) { array = arrayMap(array, baseUnary(iteratee)); } - var length = array.length; - maxLength = length < maxLength ? length : maxLength; - caches[othIndex] = !comparator && (iteratee || length >= 120) + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) ? new SetCache(othIndex && array) : undefined; } array = arrays[0]; - length = array.length; var index = -1, seen = caches[0];