feat(lua): add vim.func._memoize

Memoizes a function, using a custom function to hash the arguments.

Private for now until:

- There are other places in the codebase that could benefit from this
  (e.g. LSP), but might require other changes to accommodate.
- Invalidation of the cache needs to be controllable. Using weak tables
  is an acceptable invalidation policy, but it shouldn't be the only
  one.
- I don't think the story around `hash_fn` is completely thought out. We
  may be able to have a good default hash_fn by hashing each argument,
  so basically a better 'concat'.
This commit is contained in:
Lewis Russell
2023-09-16 23:10:30 +01:00
committed by Lewis Russell
parent 11865dbe39
commit 877d04d0fb
8 changed files with 137 additions and 73 deletions

View File

@ -29,6 +29,7 @@ for k, v in pairs({
treesitter = true,
filetype = true,
loader = true,
func = true,
F = true,
lsp = true,
highlight = true,