function defaultEqualityCheck(a, b) {
return a === b
}
function defaultMemoize_original(func, equalityCheck = defaultEqualityCheck) {
let lastArgs = null
let lastResult = null
return (...args) => {
if (
lastArgs === null ||
lastArgs.length !== args.length ||
!args.every((value, index) => equalityCheck(value, lastArgs[index]))
) {
lastResult = func(...args)
}
lastArgs = args
return lastResult
}
}
function defaultMemoize_optimized(func, equalityCheck = defaultEqualityCheck) {
const isEqual = (value, index) => equalityCheck(value, lastArgs[index])
let lastArgs = null
let lastResult = null
return (...args) => {
if (
lastArgs === null ||
lastArgs.length !== args.length ||
!args.every(isEqual)
) {
lastResult = func(...args)
}
lastArgs = args
return lastResult
}
}
function combine(a, b) {
return { combined: a + b };
}
var combine_original = defaultMemoize_original(combine);
var combine_optimized = defaultMemoize_optimized(combine);
var NUM_REPEAT = 50000;