* Check whether (name, args) was just executed. Returns the cached result * or null. Only deduplicates pure tools.
(name, args)
| 91 | * or null. Only deduplicates pure tools. |
| 92 | */ |
| 93 | lookup(name, args) { |
| 94 | if (this.disabled) return null; |
| 95 | if (!PURE_TOOLS.has(name)) return null; |
| 96 | const h = this._hash(name, args); |
| 97 | for (let i = this.recent.length - 1; i >= 0; i--) { |
| 98 | if (this.recent[i].hash === h) { |
| 99 | this.hits++; |
| 100 | // Return a shallow copy so callers can't mutate the cached entry |
| 101 | return { ...this.recent[i].result }; |
| 102 | } |
| 103 | } |
| 104 | this.misses++; |
| 105 | return null; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Record the (name, args, result) of a just-executed call. |
no test coverage detected