MCPcopy
hub / github.com/webpack/webpack / cachedProvide

Method cachedProvide

lib/util/WeakTupleMap.js:144–154  ·  view source on GitHub ↗

* Memoizes `compute(thisArg, ...args)` under the tuple key `[compute, * ...args]`, computing it on a miss. Equivalent to `provide(compute, ...args, * () => compute(thisArg, ...args))` but without allocating that closure (or an * extra rest array) on every call — `ModuleGraph#cached` runs this

(compute, thisArg, args)

Source from the content-addressed store, hash-verified

142 * @returns {V} the value
143 */
144 cachedProvide(compute, thisArg, args) {
145 /** @type {WeakTupleMap<K, V>} */
146 let node = this._get(/** @type {ArrayElement<K>} */ (compute));
147 for (let i = 0; i < args.length; i++) {
148 node = node._get(/** @type {ArrayElement<K>} */ (args[i]));
149 }
150 if (node._hasValue()) return /** @type {V} */ (node._getValue());
151 const newValue = compute(thisArg, ...args);
152 node._setValue(newValue);
153 return newValue;
154 }
155
156 /**
157 * Removes the value stored for the tuple key without pruning the trie.

Callers 1

cachedMethod · 0.80

Calls 5

_getMethod · 0.95
computeFunction · 0.85
_hasValueMethod · 0.80
_getValueMethod · 0.80
_setValueMethod · 0.80

Tested by

no test coverage detected