From eaee1882449e80bee976026949039bd05398aa65 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 29 Jul 2014 08:47:23 -0700 Subject: [PATCH] Use `resIndex` where applied easily. --- lodash.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lodash.js b/lodash.js index b8afb9522..e5b420010 100644 --- a/lodash.js +++ b/lodash.js @@ -1165,12 +1165,13 @@ function arrayFilter(array, predicate) { var index = -1, length = array.length, + resIndex = -1, result = []; while (++index < length) { var value = array[index]; if (predicate(value, index, array)) { - result.push(value); + result[++resIndex] = value; } } return result; @@ -1928,12 +1929,13 @@ var index = -1, props = keysFunc(object), length = props.length, + resIndex = -1, result = []; while (++index < length) { var key = props[index]; if (isFunction(object[key])) { - result.push(key); + result[++resIndex] = key; } } return result; @@ -2958,12 +2960,13 @@ function replaceHolders(array, placeholder) { var index = -1, length = array.length, + resIndex = -1, result = []; while (++index < length) { if (array[index] === placeholder) { array[index] = PLACEHOLDER; - result.push(index); + result[++resIndex] = index; } } return result; @@ -3068,6 +3071,7 @@ var seen, index = -1, length = array.length, + resIndex = -1, result = []; while (++index < length) { @@ -3076,7 +3080,7 @@ if (!index || seen !== computed) { seen = computed; - result.push(value); + result[++resIndex] = value; } } return result; @@ -3142,11 +3146,12 @@ function chunk(array, chunkSize) { var index = 0, length = array ? array.length : 0, + resIndex = -1, result = []; chunkSize = nativeMax(+chunkSize || 1, 1); while (index < length) { - result.push(slice(array, index, (index += chunkSize))); + result[++resIndex] = slice(array, index, (index += chunkSize)); } return result; }