Download pool/shard004/JavaScript/0025216_mergeData.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 3.08 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/JavaScript/0025216_mergeData.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard004/JavaScript/0025216_mergeData.js
-
curl -L -o 0025216_mergeData.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/JavaScript/0025216_mergeData.js
3.08 kB
| ; | |
| const composeArgs = require('./_composeArgs'); | |
| const composeArgsRight = require('./_composeArgsRight'); | |
| const replaceHolders = require('./_replaceHolders'); | |
| /** Used as the internal argument placeholder. */ | |
| const PLACEHOLDER = '__lodash_placeholder__'; | |
| /** Used to compose bitmasks for wrapper metadata. */ | |
| const BIND_FLAG = 1; | |
| const BIND_KEY_FLAG = 2; | |
| const CURRY_BOUND_FLAG = 4; | |
| const CURRY_FLAG = 8; | |
| const ARY_FLAG = 128; | |
| const REARG_FLAG = 256; | |
| /* Built-in method references for those with the same name as other `lodash` methods. */ | |
| const nativeMin = Math.min; | |
| /** | |
| * Merges the function metadata of `source` into `data`. | |
| * | |
| * Merging metadata reduces the number of wrappers used to invoke a function. | |
| * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` | |
| * may be applied regardless of execution order. Methods like `_.ary` and | |
| * `_.rearg` modify function arguments, making the order in which they are | |
| * executed important, preventing the merging of metadata. However, we make | |
| * an exception for a safe combined case where curried functions have `_.ary` | |
| * and or `_.rearg` applied. | |
| * | |
| * @private | |
| * @param {Array} data The destination metadata. | |
| * @param {Array} source The source metadata. | |
| * @returns {Array} Returns `data`. | |
| */ | |
| function mergeData(data, source) { | |
| const bitmask = data[1]; | |
| const srcBitmask = source[1]; | |
| let newBitmask = bitmask | srcBitmask; | |
| const isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG); | |
| const isCombo = | |
| ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) || | |
| ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) || | |
| ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG)); | |
| // Exit early if metadata can't be merged. | |
| if (!(isCommon || isCombo)) { | |
| return data; | |
| } | |
| // Use source `thisArg` if available. | |
| if (srcBitmask & BIND_FLAG) { | |
| data[2] = source[2]; | |
| // Set when currying a bound function. | |
| newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG; | |
| } | |
| // Compose partial arguments. | |
| let value = source[3]; | |
| if (value) { | |
| var partials = data[3]; | |
| data[3] = partials ? composeArgs(partials, value, source[4]) : value; | |
| data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; | |
| } | |
| // Compose partial right arguments. | |
| value = source[5]; | |
| if (value) { | |
| partials = data[5]; | |
| data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; | |
| data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; | |
| } | |
| // Use source `argPos` if available. | |
| value = source[7]; | |
| if (value) { | |
| data[7] = value; | |
| } | |
| // Use source `ary` if it's smaller. | |
| if (srcBitmask & ARY_FLAG) { | |
| data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); | |
| } | |
| // Use source `arity` if one is not provided. | |
| if (data[9] == null) { | |
| data[9] = source[9]; | |
| } | |
| // Use source `func` and merge bitmasks. | |
| data[0] = source[0]; | |
| data[1] = newBitmask; | |
| return data; | |
| } | |
| module.exports = mergeData; | |