Skip to content

Commit

Permalink
fix(lru): use map.delete() directly (#713)
Browse files Browse the repository at this point in the history
The default implementation already returns boolean if the value has been
deleted.


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete#return_value

It's also faster since we don't double check the hashmap for a value.

---------

Co-authored-by: Luke Karrys <luke@lukekarrys.com>
  • Loading branch information
negezor and lukekarrys committed May 9, 2024
1 parent d777418 commit 6466ba9
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions internal/lrucache.js
Expand Up @@ -17,12 +17,7 @@ class LRUCache {
}

delete (key) {
if (this.map.has(key)) {
this.map.delete(key)
return true
} else {
return false
}
return this.map.delete(key)
}

set (key, value) {
Expand Down

0 comments on commit 6466ba9

Please sign in to comment.