MCPcopy
hub / github.com/webpack/webpack / cachedFn

Function cachedFn

lib/util/identifier.js:189–213  ·  view source on GitHub ↗
(context, identifier, associatedObjectForCache)

Source from the content-addressed store, hash-verified

187
188 /** @type {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} */
189 const cachedFn = (context, identifier, associatedObjectForCache) => {
190 if (!associatedObjectForCache) return fn(context, identifier);
191
192 let innerCache = cache.get(associatedObjectForCache);
193 if (innerCache === undefined) {
194 innerCache = new Map();
195 cache.set(associatedObjectForCache, innerCache);
196 }
197
198 /** @type {undefined | string} */
199 let cachedResult;
200 let innerSubCache = innerCache.get(context);
201 if (innerSubCache === undefined) {
202 innerCache.set(context, (innerSubCache = new Map()));
203 } else {
204 cachedResult = innerSubCache.get(identifier);
205 }
206
207 if (cachedResult !== undefined) {
208 return cachedResult;
209 }
210 const result = fn(context, identifier);
211 innerSubCache.set(identifier, result);
212 return result;
213 };
214
215 /** @type {BindCacheForContext} */
216 cachedFn.bindCache = (associatedObjectForCache) => {

Callers

nothing calls this directly

Calls 3

fnFunction · 0.70
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected