diff --git a/.internal/arrayLikeKeys.js b/.internal/arrayLikeKeys.js index f926127c7..d0f3a742e 100644 --- a/.internal/arrayLikeKeys.js +++ b/.internal/arrayLikeKeys.js @@ -1,4 +1,3 @@ -import baseTimes from './baseTimes.js' import isArguments from '../isArguments.js' import isBuffer from '../isBuffer.js' import isIndex from './isIndex.js' @@ -21,9 +20,12 @@ function arrayLikeKeys(value, inherited) { const isBuff = !isArr && !isArg && isBuffer(value) const isType = !isArr && !isArg && !isBuff && isTypedArray(value) const skipIndexes = isArr || isArg || isBuff || isType - const result = skipIndexes ? baseTimes(value.length, String) : [] - const length = result.length - + const length = value.length + const result = new Array(skipIndexes ? length : 0) + let index = skipIndexes ? -1 : length + while (++index < length) { + result[index] = `${ index }` + } for (const key in value) { if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && ( diff --git a/.internal/baseTimes.js b/.internal/baseTimes.js deleted file mode 100644 index c1ab24168..000000000 --- a/.internal/baseTimes.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * The base implementation of `times` without support for max array length checks. - * - * @private - * @param {number} n The number of times to invoke `iteratee`. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the array of results. - */ -function baseTimes(n, iteratee) { - let index = -1 - const result = Array(n) - - while (++index < n) { - result[index] = iteratee(index) - } - return result -} - -export default baseTimes diff --git a/times.js b/times.js index fecbe0519..e403762be 100644 --- a/times.js +++ b/times.js @@ -1,4 +1,3 @@ -import baseTimes from './.internal/baseTimes.js' import toInteger from './toInteger.js' /** Used as references for various `Number` constants. */ @@ -7,9 +6,6 @@ const MAX_SAFE_INTEGER = 9007199254740991 /** Used as references for the maximum length and index of an array. */ const MAX_ARRAY_LENGTH = 4294967295 -/* Built-in method references for those with the same name as other `lodash` methods. */ -const nativeMin = Math.min - /** * Invokes the iteratee `n` times, returning an array of the results of * each invocation. The iteratee is invoked with one argumentindex). @@ -32,10 +28,13 @@ function times(n, iteratee) { if (n < 1 || n > MAX_SAFE_INTEGER) { return [] } - let index = MAX_ARRAY_LENGTH - const length = nativeMin(n, MAX_ARRAY_LENGTH) - const result = baseTimes(length, iteratee) - + let index = -1 + const length = Math.min(n, MAX_ARRAY_LENGTH) + const result = Array(length) + while (++index < length) { + result[index] = iteratee(index) + } + index = MAX_ARRAY_LENGTH n -= MAX_ARRAY_LENGTH while (++index < n) { iteratee(index) diff --git a/unzip.js b/unzip.js index a5223e809..3b96b3015 100644 --- a/unzip.js +++ b/unzip.js @@ -1,7 +1,6 @@ import arrayFilter from './.internal/arrayFilter.js' import arrayMap from './.internal/arrayMap.js' import baseProperty from './.internal/baseProperty.js' -import baseTimes from './.internal/baseTimes.js' import isArrayLikeObject from './isArrayLikeObject.js' /* Built-in method references for those with the same name as other `lodash` methods. */ @@ -36,7 +35,12 @@ function unzip(array) { return true } }) - return baseTimes(length, (index) => arrayMap(array, baseProperty(index))) + let index = -1 + const result = new Array(length) + while (++index < length) { + result[index] = arrayMap(array, baseProperty(index)) + } + return result } export default unzip