* 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)
| 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. |