aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorNull Chilly <56817415+nullchilly@users.noreply.github.com>2023-03-10 20:10:38 +0700
committerGitHub <noreply@github.com>2023-03-10 14:10:38 +0100
commit75537768ef0b8cc35ef9c6aa906237e449640b46 (patch)
treeb51bfd80f1f468592640a12f6e40e0ca3bcb4136 /runtime/lua/vim
parent8a3220ba499c4c8cd74a3896f3c79e5f3d666eba (diff)
downloadrneovim-75537768ef0b8cc35ef9c6aa906237e449640b46.tar.gz
rneovim-75537768ef0b8cc35ef9c6aa906237e449640b46.tar.bz2
rneovim-75537768ef0b8cc35ef9c6aa906237e449640b46.zip
perf(lsp): better binary search mid calculation in semantic token (#22607)
This commit replaces the usage of math.floor((lo + hi) / 2) with the faster and equivalent bit.rshift(lo + hi, 1) for calculating the midpoint in binary search.
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua4
1 files changed, 2 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index a5e007a011..03532c33b7 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -44,7 +44,7 @@ local STHighlighter = { active = {} }
---@private
local function lower_bound(tokens, line, lo, hi)
while lo < hi do
- local mid = math.floor((lo + hi) / 2)
+ local mid = bit.rshift(lo + hi, 1) -- Equivalent to floor((lo + hi) / 2).
if tokens[mid].line < line then
lo = mid + 1
else
@@ -62,7 +62,7 @@ end
---@private
local function upper_bound(tokens, line, lo, hi)
while lo < hi do
- local mid = math.floor((lo + hi) / 2)
+ local mid = bit.rshift(lo + hi, 1) -- Equivalent to floor((lo + hi) / 2).
if line < tokens[mid].line then
hi = mid
else