MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / mergeData

Function mergeData

lib/web/jshint.js:5725–5778  ·  view source on GitHub ↗

* Merges the function metadata of `source` into `data`. * * Merging metadata reduces the number of wrappers required to invoke a function. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` * may be applied regardless of execution order. Methods like `_.

(data, source)

Source from the content-addressed store, hash-verified

5723 * @returns {Array} Returns `data`.
5724 */
5725 function mergeData(data, source) {
5726 var bitmask = data[1],
5727 srcBitmask = source[1],
5728 newBitmask = bitmask | srcBitmask,
5729 isCommon = newBitmask < ARY_FLAG;
5730
5731 var isCombo =
5732 (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
5733 (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
5734 (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
5735
5736 // Exit early if metadata can't be merged.
5737 if (!(isCommon || isCombo)) {
5738 return data;
5739 }
5740 // Use source `thisArg` if available.
5741 if (srcBitmask & BIND_FLAG) {
5742 data[2] = source[2];
5743 // Set when currying a bound function.
5744 newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
5745 }
5746 // Compose partial arguments.
5747 var value = source[3];
5748 if (value) {
5749 var partials = data[3];
5750 data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
5751 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
5752 }
5753 // Compose partial right arguments.
5754 value = source[5];
5755 if (value) {
5756 partials = data[5];
5757 data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
5758 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
5759 }
5760 // Use source `argPos` if available.
5761 value = source[7];
5762 if (value) {
5763 data[7] = arrayCopy(value);
5764 }
5765 // Use source `ary` if it's smaller.
5766 if (srcBitmask & ARY_FLAG) {
5767 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
5768 }
5769 // Use source `arity` if one is not provided.
5770 if (data[9] == null) {
5771 data[9] = source[9];
5772 }
5773 // Use source `func` and merge bitmasks.
5774 data[0] = source[0];
5775 data[1] = newBitmask;
5776
5777 return data;
5778 }
5779
5780 /**
5781 * A specialized version of `_.pick` that picks `object` properties specified

Callers 1

createWrapperFunction · 0.85

Calls 4

composeArgsFunction · 0.85
arrayCopyFunction · 0.85
replaceHoldersFunction · 0.85
composeArgsRightFunction · 0.85

Tested by

no test coverage detected