MCPcopy
hub / github.com/webpack/webpack / createCachedParameterizedComparator

Function createCachedParameterizedComparator

lib/util/comparators.js:58–74  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

56 * @returns {ParameterizedComparator<TArg, T>} comparator
57 */
58const createCachedParameterizedComparator = (fn) => {
59 /** @type {WeakMap<TArg, Comparator<T>>} */
60 const map = new WeakMap();
61 return (arg) => {
62 const cachedResult = map.get(arg);
63 if (cachedResult !== undefined) return cachedResult;
64 // arrow closure dispatches faster than a bound function on the sort hot path
65 /**
66 * @param {T} a first item
67 * @param {T} b second item
68 * @returns {-1 | 0 | 1} compare result
69 */
70 const result = (a, b) => fn(arg, a, b);
71 map.set(arg, result);
72 return result;
73 };
74};
75
76/**
77 * Compares the provided values and returns their ordering.

Callers 1

comparators.jsFile · 0.85

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected