Skip to content

perf(util): small perf optims#961

Open
Kalmaegi wants to merge 1 commit into
folke:mainfrom
Kalmaegi:main
Open

perf(util): small perf optims#961
Kalmaegi wants to merge 1 commit into
folke:mainfrom
Kalmaegi:main

Conversation

@Kalmaegi
Copy link
Copy Markdown

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 Kalmaegi changed the title perf: small perf optims perf(util): small perf optims Mar 16, 2025
@github-actions
Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Apr 16, 2025
iSplasher added a commit to isplasher-forks/which-key.nvim that referenced this pull request Jun 20, 2025
iSplasher added a commit to isplasher-forks/which-key.nvim that referenced this pull request Jun 20, 2025
@ashb
Copy link
Copy Markdown

ashb commented Aug 14, 2025

Not stale

@github-actions github-actions Bot removed the stale This issue or PR has been inactive for a while label Aug 15, 2025
@github-actions
Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the stale This issue or PR has been inactive for a while label Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue or PR has been inactive for a while

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants