MCPcopy Create free account
hub / github.com/Effect-TS/effect / withCache

Function withCache

packages/effect/src/Equal.ts:290–314  ·  view source on GitHub ↗
(self: object, that: object, f: (a: any, b: any) => boolean)

Source from the content-addressed store, hash-verified

288}
289
290function withCache(self: object, that: object, f: (a: any, b: any) => boolean): boolean {
291 // Check cache first
292 let selfMap = equalityCache.get(self)
293 if (!selfMap) {
294 selfMap = new WeakMap()
295 equalityCache.set(self, selfMap)
296 } else if (selfMap.has(that)) {
297 return selfMap.get(that)!
298 }
299
300 // Perform the comparison
301 const result = f(self, that)
302
303 // Cache the result bidirectionally
304 selfMap.set(that, result)
305
306 let thatMap = equalityCache.get(that)
307 if (!thatMap) {
308 thatMap = new WeakMap()
309 equalityCache.set(that, thatMap)
310 }
311 thatMap.set(self, result)
312
313 return result
314}
315
316const equalityCache = new WeakMap<object, WeakMap<object, boolean>>()
317

Callers 1

compareBothFunction · 0.85

Calls 4

getMethod · 0.65
setMethod · 0.65
fFunction · 0.50
hasMethod · 0.45

Tested by

no test coverage detected