mirror of
https://github.com/hrsh7th/nvim-cmp
synced 2024-09-16 20:54:03 +02:00
perf(core): simplify and improve find_line_suffix()
(#1675)
Call `string.match()` once instead of calling `string.sub()` and `string.find()` multiple times in a loop.
This commit is contained in:
parent
992fa0dd47
commit
969c5affa5
1 changed files with 7 additions and 9 deletions
|
@ -189,16 +189,14 @@ core.on_moved = function(self)
|
|||
self:filter()
|
||||
end
|
||||
|
||||
-- Find the suffix for the specified line
|
||||
---Returns the suffix of the specified `line`.
|
||||
---
|
||||
---Contains `%s`: returns everything after the last `%s` in `line`
|
||||
---Else: returns `line` unmodified
|
||||
---@param line string
|
||||
---@return string suffix
|
||||
local function find_line_suffix(line)
|
||||
local i = #line
|
||||
while i > 0 do
|
||||
if line:sub(i, i):find('%s') then
|
||||
return line:sub(i + 1)
|
||||
end
|
||||
i = i - 1
|
||||
end
|
||||
return line
|
||||
return line:match('%S*$') --[[@as string]]
|
||||
end
|
||||
|
||||
---Check autoindent
|
||||
|
|
Loading…
Reference in a new issue