mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
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:
committed by
Lewis Russell
parent
11865dbe39
commit
877d04d0fb
@ -361,6 +361,12 @@ local function process_line(line, in_stream, generics)
|
||||
return process_block_comment(line:sub(5), in_stream)
|
||||
end
|
||||
|
||||
-- Hax... I'm sorry
|
||||
-- M.fun = vim.memoize(function(...)
|
||||
-- ->
|
||||
-- function M.fun(...)
|
||||
line = line:gsub('^(.+) = .*_memoize%([^,]+, function%((.*)%)$', 'function %1(%2)')
|
||||
|
||||
if line:find('^function') or line:find('^local%s+function') then
|
||||
return process_function_header(line)
|
||||
end
|
||||
|
Reference in New Issue
Block a user