mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Replace arrayCopy and baseCopy with copyArray, copyObject, and copyObjectWith.
This commit is contained in:
148
lodash.src.js
148
lodash.src.js
@@ -1164,12 +1164,12 @@
|
|||||||
*/
|
*/
|
||||||
function lazyClone() {
|
function lazyClone() {
|
||||||
var result = new LazyWrapper(this.__wrapped__);
|
var result = new LazyWrapper(this.__wrapped__);
|
||||||
result.__actions__ = arrayCopy(this.__actions__);
|
result.__actions__ = copyArray(this.__actions__);
|
||||||
result.__dir__ = this.__dir__;
|
result.__dir__ = this.__dir__;
|
||||||
result.__filtered__ = this.__filtered__;
|
result.__filtered__ = this.__filtered__;
|
||||||
result.__iteratees__ = arrayCopy(this.__iteratees__);
|
result.__iteratees__ = copyArray(this.__iteratees__);
|
||||||
result.__takeCount__ = this.__takeCount__;
|
result.__takeCount__ = this.__takeCount__;
|
||||||
result.__views__ = arrayCopy(this.__views__);
|
result.__views__ = copyArray(this.__views__);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1397,25 +1397,6 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the values of `source` to `array`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Array} source The array to copy values from.
|
|
||||||
* @param {Array} [array=[]] The array to copy values to.
|
|
||||||
* @returns {Array} Returns `array`.
|
|
||||||
*/
|
|
||||||
function arrayCopy(source, array) {
|
|
||||||
var index = -1,
|
|
||||||
length = source.length;
|
|
||||||
|
|
||||||
array || (array = Array(length));
|
|
||||||
while (++index < length) {
|
|
||||||
array[index] = source[index];
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized version of `_.forEach` for arrays without support for callback
|
* A specialized version of `_.forEach` for arrays without support for callback
|
||||||
* shorthands and `this` binding.
|
* shorthands and `this` binding.
|
||||||
@@ -1768,30 +1749,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies properties of `source` to `object`.
|
* The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
||||||
*
|
* traversed objects.
|
||||||
* @private
|
|
||||||
* @param {Object} source The object to copy properties from.
|
|
||||||
* @param {Array} props The property names to copy.
|
|
||||||
* @param {Object} [object={}] The object to copy properties to.
|
|
||||||
* @returns {Object} Returns `object`.
|
|
||||||
*/
|
|
||||||
function baseCopy(source, props, object) {
|
|
||||||
object || (object = {});
|
|
||||||
|
|
||||||
var index = -1,
|
|
||||||
length = props.length;
|
|
||||||
|
|
||||||
while (++index < length) {
|
|
||||||
var key = props[index];
|
|
||||||
object[key] = source[key];
|
|
||||||
}
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base implementation of `_.clone` without support for argument juggling
|
|
||||||
* and `this` binding `customizer` functions.
|
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {*} value The value to clone.
|
* @param {*} value The value to clone.
|
||||||
@@ -1818,7 +1777,7 @@
|
|||||||
if (isArr) {
|
if (isArr) {
|
||||||
result = initCloneArray(value);
|
result = initCloneArray(value);
|
||||||
if (!isDeep) {
|
if (!isDeep) {
|
||||||
return arrayCopy(value, result);
|
return copyArray(value, result);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var tag = objToString.call(value),
|
var tag = objToString.call(value),
|
||||||
@@ -2491,7 +2450,7 @@
|
|||||||
if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
|
if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
|
||||||
result = isArray(value)
|
result = isArray(value)
|
||||||
? value
|
? value
|
||||||
: (isArrayLike(value) ? arrayCopy(value) : []);
|
: (isArrayLike(value) ? copyArray(value) : []);
|
||||||
}
|
}
|
||||||
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
||||||
result = isArguments(value)
|
result = isArguments(value)
|
||||||
@@ -2985,6 +2944,77 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the values of `source` to `array`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Array} source The array to copy values from.
|
||||||
|
* @param {Array} [array=[]] The array to copy values to.
|
||||||
|
* @returns {Array} Returns `array`.
|
||||||
|
*/
|
||||||
|
function copyArray(source, array) {
|
||||||
|
var index = -1,
|
||||||
|
length = source.length;
|
||||||
|
|
||||||
|
array || (array = Array(length));
|
||||||
|
while (++index < length) {
|
||||||
|
array[index] = source[index];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies properties of `source` to `object`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} source The object to copy properties from.
|
||||||
|
* @param {Array} props The property names to copy.
|
||||||
|
* @param {Object} [object={}] The object to copy properties to.
|
||||||
|
* @returns {Object} Returns `object`.
|
||||||
|
*/
|
||||||
|
function copyObject(source, props, object) {
|
||||||
|
object || (object = {});
|
||||||
|
|
||||||
|
var index = -1,
|
||||||
|
length = props.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
var key = props[index];
|
||||||
|
object[key] = source[key];
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is like `copyObject` except that it accepts a function to
|
||||||
|
* customize copied values.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} source The object to copy properties from.
|
||||||
|
* @param {Array} props The property names to copy.
|
||||||
|
* @param {Function} customizer The function to customize copied values.
|
||||||
|
* @param {Object} [object={}] The object to copy properties to.
|
||||||
|
* @returns {Object} Returns `object`.
|
||||||
|
*/
|
||||||
|
function copyObjectWith(source, props, customizer, object) {
|
||||||
|
object || (object = {});
|
||||||
|
|
||||||
|
var index = -1,
|
||||||
|
length = props.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
var key = props[index],
|
||||||
|
value = object[key],
|
||||||
|
result = customizer(value, source[key], key, object, source);
|
||||||
|
|
||||||
|
if ((result === result ? (result !== value) : (value === value)) ||
|
||||||
|
(value === undefined && !(key in object))) {
|
||||||
|
object[key] = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
|
* Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
|
||||||
*
|
*
|
||||||
@@ -3300,7 +3330,7 @@
|
|||||||
|
|
||||||
length -= argsHolders.length;
|
length -= argsHolders.length;
|
||||||
if (length < arity) {
|
if (length < arity) {
|
||||||
var newArgPos = argPos ? arrayCopy(argPos) : undefined,
|
var newArgPos = argPos ? copyArray(argPos) : undefined,
|
||||||
newArity = nativeMax(arity - length, 0),
|
newArity = nativeMax(arity - length, 0),
|
||||||
newsHolders = isCurry ? argsHolders : undefined,
|
newsHolders = isCurry ? argsHolders : undefined,
|
||||||
newHoldersRight = isCurry ? undefined : argsHolders,
|
newHoldersRight = isCurry ? undefined : argsHolders,
|
||||||
@@ -3453,7 +3483,7 @@
|
|||||||
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
|
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
|
||||||
partials = holders = undefined;
|
partials = holders = undefined;
|
||||||
}
|
}
|
||||||
length -= (holders ? holders.length : 0);
|
length -= holders ? holders.length : 0;
|
||||||
if (bitmask & PARTIAL_RIGHT_FLAG) {
|
if (bitmask & PARTIAL_RIGHT_FLAG) {
|
||||||
var partialsRight = partials,
|
var partialsRight = partials,
|
||||||
holdersRight = holders;
|
holdersRight = holders;
|
||||||
@@ -4011,20 +4041,20 @@
|
|||||||
var value = source[3];
|
var value = source[3];
|
||||||
if (value) {
|
if (value) {
|
||||||
var partials = data[3];
|
var partials = data[3];
|
||||||
data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
|
data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value);
|
||||||
data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
|
data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(source[4]);
|
||||||
}
|
}
|
||||||
// Compose partial right arguments.
|
// Compose partial right arguments.
|
||||||
value = source[5];
|
value = source[5];
|
||||||
if (value) {
|
if (value) {
|
||||||
partials = data[5];
|
partials = data[5];
|
||||||
data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
|
data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value);
|
||||||
data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
|
data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(source[6]);
|
||||||
}
|
}
|
||||||
// Use source `argPos` if available.
|
// Use source `argPos` if available.
|
||||||
value = source[7];
|
value = source[7];
|
||||||
if (value) {
|
if (value) {
|
||||||
data[7] = arrayCopy(value);
|
data[7] = copyArray(value);
|
||||||
}
|
}
|
||||||
// Use source `ary` if it's smaller.
|
// Use source `ary` if it's smaller.
|
||||||
if (srcBitmask & ARY_FLAG) {
|
if (srcBitmask & ARY_FLAG) {
|
||||||
@@ -4110,7 +4140,7 @@
|
|||||||
function reorder(array, indexes) {
|
function reorder(array, indexes) {
|
||||||
var arrLength = array.length,
|
var arrLength = array.length,
|
||||||
length = nativeMin(indexes.length, arrLength),
|
length = nativeMin(indexes.length, arrLength),
|
||||||
oldArray = arrayCopy(array);
|
oldArray = copyArray(array);
|
||||||
|
|
||||||
while (length--) {
|
while (length--) {
|
||||||
var index = indexes[length];
|
var index = indexes[length];
|
||||||
@@ -4260,7 +4290,7 @@
|
|||||||
function wrapperClone(wrapper) {
|
function wrapperClone(wrapper) {
|
||||||
return wrapper instanceof LazyWrapper
|
return wrapper instanceof LazyWrapper
|
||||||
? wrapper.clone()
|
? wrapper.clone()
|
||||||
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
|
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, copyArray(wrapper.__actions__));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
@@ -8528,7 +8558,7 @@
|
|||||||
}
|
}
|
||||||
return (lodash.support.unindexedChars && isString(value))
|
return (lodash.support.unindexedChars && isString(value))
|
||||||
? value.split('')
|
? value.split('')
|
||||||
: arrayCopy(value);
|
: copyArray(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8555,7 +8585,7 @@
|
|||||||
* // => { 'a': 1, 'b': 2, 'c': 3 }
|
* // => { 'a': 1, 'b': 2, 'c': 3 }
|
||||||
*/
|
*/
|
||||||
function toPlainObject(value) {
|
function toPlainObject(value) {
|
||||||
return baseCopy(value, keysIn(value));
|
return copyObject(value, keysIn(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user