which-key.nvim
which-key.nvim copied to clipboard
perf(util): small perf optims
I noticed that there are two similar caching patterns in the codebase with slightly different implementations. Specifically, the M.t function uses a short-circuit evaluation pattern while M.norm uses an explicit if-check:
-- M.t uses short-circuit evaluation
function M.t(str)
M.cache.termcodes[str] = M.cache.termcodes[str] or vim.api.nvim_replace_termcodes(str, true, true, true)
return M.cache.termcodes[str]
end
-- M.norm uses explicit if-check
function M.norm(lhs)
if M.cache.norm[lhs] then
return M.cache.norm[lhs]
end
M.cache.norm[lhs] = vim.fn.keytrans(M.t(lhs))
return M.cache.norm[lhs]
end
I think it might be beneficial to unify these patterns for better code consistency. I'm not sure if this small change is worth a PR, I just wanted to contribute a small improvement to this excellent plugin.
This PR is stale because it has been open 30 days with no activity.
Not stale
This PR is stale because it has been open 30 days with no activity.