MCPcopy
hub / github.com/webpack/webpack / compareSelect

Function compareSelect

lib/util/comparators.js:477–502  ·  lib/util/comparators.js::compareSelect
(getter, comparator)

Source from the content-addressed store, hash-verified

475 * @returns {Comparator<T>} comparator
476 */
477const compareSelect = (getter, comparator) => {
478 const cacheEntry = compareSelectCache.get(getter, comparator);
479 if (cacheEntry !== undefined) return cacheEntry;
480 /**
481 * Returns compare result.
482 * @param {T} a first value
483 * @param {T} b second value
484 * @returns {-1 | 0 | 1} compare result
485 */
486 const result = (a, b) => {
487 const aValue = getter(a);
488 const bValue = getter(b);
489 if (aValue !== undefined && aValue !== null) {
490 if (bValue !== undefined && bValue !== null) {
491 return comparator(aValue, bValue);
492 }
493 return -1;
494 }
495 if (bValue !== undefined && bValue !== null) {
496 return 1;
497 }
498 return 0;
499 };
500 compareSelectCache.set(getter, comparator, result);
501 return result;
502};
503
504/** @type {WeakMap<Comparator<EXPECTED_ANY>, Comparator<Iterable<EXPECTED_ANY>>>} */
505const compareIteratorsCache = new WeakMap();

Callers 12

buildMethod · 0.85
Compilation.jsFile · 0.85
runIterationMethod · 0.85
createModuleHashesMethod · 0.85
createHashMethod · 0.85
reportErrorsMethod · 0.85
applyMethod · 0.85
sortByFieldFunction · 0.85
compareChunksNaturalFunction · 0.85

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected