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 <[email protected]>
  • Loading branch information
negezor and lukekarrys authored 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
Original file line number Diff line number Diff line change
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.