caiogondim / fast-memoize.js

:rabbit2: Fastest possible memoization library

Home Page:https://npm.im/fast-memoize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: use array instead of arguments.

abritinthebay opened this issue · comments

So the default serializer does this:

function jsonStringify () {
  return JSON.stringify(arguments)
}

For cache checks (ie foo._cache.has(bar)) this makes it almost useless. It would be much easier if it converted the passed arguments object to an array and then stringified that.

function jsonStringify (args) {
  return JSON.stringify(Array.prototype.slice.call(args))
}

This would allow a key generation of just let bar = JSON.stringify(myArgsArray) which is currently only achievable by initially function wrapping to get the arguments pseudo-array.

I'm rolling with this as a custom serializer atm with no issue, would be very nice to not have to though as it presents no downside and gets away from use of the horrible arguments object too.

Interesting
Care to make a PR with a failing test so we can work on it?

Sure, may take a while to get up tho as I'm in the middle of a release ;)

Closing this issue since it's more than 30 days old.
Please let me know if you manage to push a failing test.