|
33 | 33 | /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */
|
34 | 34 | var keyPrefix = +new Date + '';
|
35 | 35 |
|
| 36 | + /** Used as the size when optimizations are enabled for large arrays */ |
| 37 | + var largeArraySize = 200; |
| 38 | + |
36 | 39 | /** Used to match empty string literals in compiled template source */
|
37 | 40 | var reEmptyStringLeading = /\b__p \+= '';/g,
|
38 | 41 | reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
|
186 | 189 | nativeMax = Math.max,
|
187 | 190 | nativeMin = Math.min,
|
188 | 191 | nativeParseInt = context.parseInt,
|
189 |
| - nativeRandom = Math.random; |
| 192 | + nativeRandom = Math.random, |
| 193 | + nativeSlice = arrayRef.slice; |
190 | 194 |
|
191 | 195 | /** Detect various environments */
|
192 | 196 | var isIeOpera = reNative.test(context.attachEvent),
|
|
570 | 574 | * @param {Array} array The array to search.
|
571 | 575 | * @param {Mixed} value The value to search for.
|
572 | 576 | * @param {Number} fromIndex The index to search from.
|
573 |
| - * @param {Number} largeSize The length at which an array is considered large. |
574 | 577 | * @returns {Boolean} Returns `true`, if `value` is found, else `false`.
|
575 | 578 | */
|
576 |
| - function cachedContains(array, fromIndex, largeSize) { |
| 579 | + function cachedContains(array, fromIndex) { |
577 | 580 | var length = array.length,
|
578 |
| - isLarge = (length - fromIndex) >= largeSize; |
| 581 | + isLarge = (length - fromIndex) >= largeArraySize; |
579 | 582 |
|
580 | 583 | if (isLarge) {
|
581 | 584 | var cache = {},
|
|
677 | 680 | }
|
678 | 681 | if (partialArgs.length) {
|
679 | 682 | args = args.length
|
680 |
| - ? (args = slice(args), rightIndicator ? args.concat(partialArgs) : partialArgs.concat(args)) |
| 683 | + ? (args = nativeSlice.call(args), rightIndicator ? args.concat(partialArgs) : partialArgs.concat(args)) |
681 | 684 | : partialArgs;
|
682 | 685 | }
|
683 | 686 | if (this instanceof bound) {
|
|
2237 | 2240 | */
|
2238 | 2241 | function at(collection) {
|
2239 | 2242 | var index = -1,
|
2240 |
| - props = concat.apply(arrayRef, slice(arguments, 1)), |
| 2243 | + props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)), |
2241 | 2244 | length = props.length,
|
2242 | 2245 | result = Array(length);
|
2243 | 2246 |
|
|
2642 | 2645 | * // => [['1', '2', '3'], ['4', '5', '6']]
|
2643 | 2646 | */
|
2644 | 2647 | function invoke(collection, methodName) {
|
2645 |
| - var args = slice(arguments, 2), |
| 2648 | + var args = nativeSlice.call(arguments, 2), |
2646 | 2649 | index = -1,
|
2647 | 2650 | isFunc = typeof methodName == 'function',
|
2648 | 2651 | length = collection ? collection.length : 0,
|
|
3280 | 3283 | var index = -1,
|
3281 | 3284 | length = array ? array.length : 0,
|
3282 | 3285 | flattened = concat.apply(arrayRef, arguments),
|
3283 |
| - contains = cachedContains(flattened, length, 100), |
| 3286 | + contains = cachedContains(flattened, length), |
3284 | 3287 | result = [];
|
3285 | 3288 |
|
3286 | 3289 | while (++index < length) {
|
|
3611 | 3614 | cache = { '0': {} },
|
3612 | 3615 | index = -1,
|
3613 | 3616 | length = array ? array.length : 0,
|
3614 |
| - isLarge = length >= 100, |
| 3617 | + isLarge = length >= largeArraySize, |
10000
3615 | 3618 | result = [],
|
3616 | 3619 | seen = result;
|
3617 | 3620 |
|
|
3630 | 3633 | }
|
3631 | 3634 | var argsIndex = argsLength;
|
3632 | 3635 | while (--argsIndex) {
|
3633 |
| - if (!(cache[argsIndex] || (cache[argsIndex] = cachedContains(args[argsIndex], 0, 100)))(value)) { |
| 3636 | + if (!(cache[argsIndex] || (cache[argsIndex] = cachedContains(args[argsIndex], 0)))(value)) { |
3634 | 3637 | continue outer;
|
3635 | 3638 | }
|
3636 | 3639 | }
|
|
4014 | 4017 | isSorted = false;
|
4015 | 4018 | }
|
4016 | 4019 | // init value cache for large arrays
|
4017 |
| - var isLarge = !isSorted && length >= 75; |
| 4020 | + var isLarge = !isSorted && length >= largeArraySize; |
4018 | 4021 | if (isLarge) {
|
4019 | 4022 | var cache = {};
|
4020 | 4023 | }
|
|
4092 | 4095 | * // => [2, 3, 4]
|
4093 | 4096 | */
|
4094 | 4097 | function without(array) {
|
4095 |
| - var index = -1, |
4096 |
| - length = array ? array.length : 0, |
4097 |
| - contains = cachedContains(arguments, 1, 30), |
4098 |
| - result = []; |
4099 |
| - |
4100 |
| - while (++index < length) { |
4101 |
| - var value = array[index]; |
4102 |
| - if (!contains(value)) { |
4103 |
| - result.push(value); |
4104 |
| - } |
4105 |
| - } |
4106 |
| - return result; |
| 4098 | + return difference(array, nativeSlice.call(arguments, 1)); |
4107 | 4099 | }
|
4108 | 4100 |
|
4109 | 4101 | /**
|
|
4229 | 4221 | // (in V8 `Function#bind` is slower except when partially applied)
|
4230 | 4222 | return support.fastBind || (nativeBind && arguments.length > 2)
|
4231 | 4223 | ? nativeBind.call.apply(nativeBind, arguments)
|
4232 |
| - : createBound(func, thisArg, slice(arguments, 2)); |
| 4224 | + : createBound(func, thisArg, nativeSlice.call(arguments, 2)); |
4233 | 4225 | }
|
4234 | 4226 |
|
4235 | 4227 | /**
|
|
4302 | 4294 | * // => 'hi, moe!'
|
4303 | 4295 | */
|
4304 | 4296 | function bindKey(object, key) {
|
4305 |
| - return createBound(object, key, slice(arguments, 2), indicatorObject); |
| 4297 | + return createBound(object, key, nativeSlice.call(arguments, 2), indicatorObject); |
4306 | 4298 | }
|
4307 | 4299 |
|
4308 | 4300 | /**
|
|
4501 | 4493 | * // returns from the function before `alert` is called
|
4502 | 4494 | */
|
4503 | 4495 | function defer(func) {
|
4504 |
| - var args = slice(arguments, 1); |
| 4496 | + var args = nativeSlice.call(arguments, 1); |
4505 | 4497 | return setTimeout(function() { func.apply(undefined, args); }, 1);
|
4506 | 4498 | }
|
4507 | 4499 | // use `setImmediate` if it's available in Node.js
|
|
4527 | 4519 | * // => 'logged later' (Appears after one second.)
|
4528 | 4520 | */
|
4529 | 4521 | function delay(func, wait) {
|
4530 |
| - var args = slice(arguments, 2); |
| 4522 | + var args = nativeSlice.call(arguments, 2); |
4531 | 4523 | return setTimeout(function() { func.apply(undefined, args); }, wait);
|
4532 | 4524 | }
|
4533 | 4525 |
|
|
4613 | 4605 | * // => 'hi moe'
|
4614 | 4606 | */
|
4615 | 4607 | function partial(func) {
|
4616 |
| - return createBound(func, slice(arguments, 1)); |
| 4608 | + return createBound(func, nativeSlice.call(arguments, 1)); |
4617 | 4609 | }
|
4618 | 4610 |
|
4619 | 4611 | /**
|
|
4644 | 4636 | * // => { '_': _, 'jq': $ }
|
4645 | 4637 | */
|
4646 | 4638 | function partialRight(func) {
|
4647 |
| - return createBound(func, slice(arguments, 1), null, indicatorObject); |
| 4639 | + return createBound(func, nativeSlice.call(arguments, 1), null, indicatorObject); |
4648 | 4640 | }
|
4649 | 4641 |
|
4650 | 4642 | /**
|
|
0 commit comments