mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
This commit is contained in:
parent
8a3220ba49
commit
75537768ef
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user