which-key.nvim icon indicating copy to clipboard operation
which-key.nvim copied to clipboard

perf(util): small perf optims

Open Kalmaegi opened this issue 10 months ago • 3 comments

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.

Kalmaegi avatar Mar 15 '25 15:03 Kalmaegi

This PR is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Apr 16 '25 02:04 github-actions[bot]

Not stale

ashb avatar Aug 14 '25 11:08 ashb

This PR is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Sep 15 '25 02:09 github-actions[bot]