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:
Tyler Miller 2023-08-11 19:52:37 -07:00 committed by GitHub
parent 992fa0dd47
commit 969c5affa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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