Adjust large array size for _.difference and cleanup large array optimization code.

Former-commit-id: c3623ce2e0639a9e98d77e36e4dae51063c76e92
This commit is contained in:
John-David Dalton
2013-03-14 14:38:48 -07:00
parent ac5d2a714e
commit 63052257a2
8 changed files with 94 additions and 110 deletions

View File

@@ -29,9 +29,6 @@
/** Used internally to indicate various things */
var indicatorObject = {};
/** Used by `cachedContains` as the default size when optimizations are enabled for large arrays */
var largeArraySize = 30;
/** Used to match empty string literals in compiled template source */
var reEmptyStringLeading = /\b__p \+= '';/g,
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
@@ -584,15 +581,13 @@
* @private
* @param {Array} array The array to search.
* @param {Mixed} value The value to search for.
* @param {Number} [fromIndex=0] The index to search from.
* @param {Number} [largeSize=30] The length at which an array is considered large.
* @param {Number} fromIndex The index to search from.
* @param {Number} largeSize The length at which an array is considered large.
* @returns {Boolean} Returns `true`, if `value` is found, else `false`.
*/
function cachedContains(array, fromIndex, largeSize) {
fromIndex || (fromIndex = 0);
var length = array.length,
isLarge = (length - fromIndex) >= (largeSize || largeArraySize);
isLarge = (length - fromIndex) >= largeSize;
if (isLarge) {
var cache = {},
@@ -3250,7 +3245,7 @@
var index = -1,
length = array ? array.length : 0,
flattened = concat.apply(arrayRef, arguments),
contains = cachedContains(flattened, length),
contains = cachedContains(flattened, length, 100),
result = [];
while (++index < length) {
@@ -4000,7 +3995,7 @@
function without(array) {
var index = -1,
length = array ? array.length : 0,
contains = cachedContains(arguments, 1),
contains = cachedContains(arguments, 1, 30),
result = [];
while (++index < length) {