MCPcopy
hub / github.com/josdejong/mathjs / memoizeCompare

Function memoizeCompare

src/utils/function.js:64–89  ·  view source on GitHub ↗
(fn, isEqual)

Source from the content-addressed store, hash-verified

62 * @returns {function}
63 */
64export function memoizeCompare (fn, isEqual) {
65 const memoize = function memoize () {
66 const args = []
67 for (let i = 0; i < arguments.length; i++) {
68 args[i] = arguments[i]
69 }
70
71 for (let c = 0; c < memoize.cache.length; c++) {
72 const cached = memoize.cache[c]
73
74 if (isEqual(args, cached.args)) {
75 // TODO: move this cache entry to the top so recently used entries move up?
76 return cached.res
77 }
78 }
79
80 const res = fn.apply(fn, args)
81 memoize.cache.unshift({ args, res })
82
83 return res
84 }
85
86 memoize.cache = []
87
88 return memoize
89}

Callers 1

function.test.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…