Skip to content

Commit bfcb9a1

Browse files
committed
Don't create new LRUCache when not needed
If you call hit() on an item that's not actually in the LRUCache (edge case), it's a no-op, so we can just return this.
1 parent ba8b64b commit bfcb9a1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/reactor/cache.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ export class LRUCache {
140140
* @return {LRUCache}
141141
*/
142142
hit(item) {
143-
// if item exists, remove it first to reorder in lru OrderedSet
144-
const lru = this.cache.lookup(item) ?
145-
this.lru.remove(item).add(item) :
146-
this.lru;
143+
if (!this.cache.has(item)) {
144+
return this;
145+
}
147146

148-
return new LRUCache(this.limit, this.cache, lru)
147+
// remove it first to reorder in lru OrderedSet
148+
return new LRUCache(this.limit, this.cache, this.lru.remove(item).add(item))
149149
}
150150

151151
/**

0 commit comments

Comments
 (0)