From 8e9a244cddf1c35d125fbdbdac1f66c331b0dd08 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 1 Jul 2013 22:44:21 -0700 Subject: [PATCH] Simplify `createCache` bailout. Former-commit-id: 2d72da41abfd2bf83017534d841444d99b47776b --- lodash.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lodash.js b/lodash.js index caadb5102..349f8b956 100644 --- a/lodash.js +++ b/lodash.js @@ -220,9 +220,7 @@ typeCache = cache[type] || (cache[type] = {}); if (type == 'object') { - if ((typeCache[key] || (typeCache[key] = [])).push(value) == this.array.length) { - cache[type] = false; - } + (typeCache[key] || (typeCache[key] = [])).push(value); } else { typeCache[key] = true; } @@ -279,8 +277,13 @@ */ function createCache(array) { var index = -1, - length = array.length; + length = array.length, + first = array[0], + last = array[length - 1]; + if (first && typeof first == 'object' && last && typeof last == 'object') { + return false; + } var cache = getObject(); cache['false'] = cache['null'] = cache['true'] = cache['undefined'] = false; @@ -292,9 +295,7 @@ while (++index < length) { result.push(array[index]); } - return cache.object === false - ? (releaseObject(result), null) - : result; + return result; } /**