diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-09-16 23:10:30 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2023-09-20 13:42:41 +0100 |
commit | 877d04d0fb83b5fc602dbab22b58f26a793ec236 (patch) | |
tree | 2f6ee1af59ae412256116d8abf28a2a6f7b6d848 /scripts/lua2dox.lua | |
parent | 11865dbe3917a538617b2b7df31bf7375e292bc8 (diff) | |
download | rneovim-877d04d0fb83b5fc602dbab22b58f26a793ec236.tar.gz rneovim-877d04d0fb83b5fc602dbab22b58f26a793ec236.tar.bz2 rneovim-877d04d0fb83b5fc602dbab22b58f26a793ec236.zip |
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'.
Diffstat (limited to 'scripts/lua2dox.lua')
-rw-r--r-- | scripts/lua2dox.lua | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/scripts/lua2dox.lua b/scripts/lua2dox.lua index 7594a0e7df..1c8bc5a3cb 100644 --- a/scripts/lua2dox.lua +++ b/scripts/lua2dox.lua @@ -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 |