diff options
author | jdrouhard <john@drouhard.dev> | 2022-12-12 11:42:37 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-12 18:42:37 +0100 |
commit | 3869a2e0cf25323a8e5235840678b147ca908517 (patch) | |
tree | af9b075afa852407ea73465838fb667a3482db88 /runtime/lua/vim/lsp/semantic_tokens.lua | |
parent | d40d34aaa5720b67da629b4ca74674dfd4b9221c (diff) | |
download | rneovim-3869a2e0cf25323a8e5235840678b147ca908517.tar.gz rneovim-3869a2e0cf25323a8e5235840678b147ca908517.tar.bz2 rneovim-3869a2e0cf25323a8e5235840678b147ca908517.zip |
perf(lsp): update semantic tokens algorithm for parsing modifiers (#21383)
Instead of testing for every possible modifier type, only test bits up
to the highest set in the token array. Saves many bit ops and
comparisons when there are no modifiers or when the highest set bit is a
lower bit than the highest possible in the legend on average.
Can be further simplified when non-luaJIT gets the full bit module (see #21222)
Diffstat (limited to 'runtime/lua/vim/lsp/semantic_tokens.lua')
-rw-r--r-- | runtime/lua/vim/lsp/semantic_tokens.lua | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index 11e62ee793..f06d136801 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -55,22 +55,22 @@ end ---@private ---@return string[] local function modifiers_from_number(x, modifiers_table) - ---@private - local function _get_bit(n, k) - --TODO(jdrouhard): remove once `bit` module is available for non-LuaJIT + local modifiers = {} + local idx = 1 + while x > 0 do if _G.bit then - return _G.bit.band(_G.bit.rshift(n, k), 1) + if _G.bit.band(x, 1) == 1 then + modifiers[#modifiers + 1] = modifiers_table[idx] + end + x = _G.bit.rshift(x, 1) else - return math.floor((n / math.pow(2, k)) % 2) - end - end - - local modifiers = {} - for i = 0, #modifiers_table - 1 do - local b = _get_bit(x, i) - if b == 1 then - modifiers[#modifiers + 1] = modifiers_table[i + 1] + --TODO(jdrouhard): remove this branch once `bit` module is available for non-LuaJIT (#21222) + if x % 2 == 1 then + modifiers[#modifiers + 1] = modifiers_table[idx] + end + x = math.floor(x / 2) end + idx = idx + 1 end return modifiers |