Closed trivikr closed 3 years ago
Hello again @trivikr. Once again, this redundant code is here for a reason. The #.setpop
method needs to allocate an object to work and will trigger garbage collection when used repeatedly, something that the #.set
method should avoid. Modern JS engines may be able to optimize for this in your example since the return value is not used by I doubt it very much :)
this redundant code is here for a reason. The
#.setpop
method needs to allocate an object to work and will trigger garbage collection when used repeatedly, something that the#.set
method should avoid.
This issue can be closed as the duplicate code exists for performance reasons.
Is your request related to a problem? Please describe.
The functions
set
andsetpop
are very similar:set
: Sets the value for the given key in the cache. https://github.com/Yomguithereal/mnemonist/blob/825538adaf1daee4b9ce3f6c073956ed4211ea1e/lru-cache.js#L107-L140setpop
: Sets the value for the given key in the cache. Returns an object containing the key and value of an item that was overwritten or evicted in the set operation, as well as a boolean indicating whether it was evicted due to limited capacity. Return value is null if nothing was evicted or overwritten during the set operation. https://github.com/Yomguithereal/mnemonist/blob/825538adaf1daee4b9ce3f6c073956ed4211ea1e/lru-cache.js#L153-L197Describe the solution you'd like
Call
setpop
from insideset
and ignore the returned value.For example, in LRUCache:
Describe alternatives you've considered
N/A
Additional context