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:
@@ -189,16 +189,14 @@ core.on_moved = function(self)
|
|||||||
self:filter()
|
self:filter()
|
||||||
end
|
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 function find_line_suffix(line)
|
||||||
local i = #line
|
return line:match('%S*$') --[[@as string]]
|
||||||
while i > 0 do
|
|
||||||
if line:sub(i, i):find('%s') then
|
|
||||||
return line:sub(i + 1)
|
|
||||||
end
|
|
||||||
i = i - 1
|
|
||||||
end
|
|
||||||
return line
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Check autoindent
|
---Check autoindent
|
||||||
|
|||||||
Reference in New Issue
Block a user