Simplify reverse search

Remove `plain_rfind` optimization.
This commit is contained in:
Guldoman 2021-10-09 00:24:48 +02:00
parent af925d603b
commit cfe0c79a04
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
1 changed files with 2 additions and 17 deletions

View File

@ -23,28 +23,13 @@ local function init_args(doc, line, col, text, opt)
end end
local function plain_rfind(text, pattern, index)
local len = #text
text = text:reverse()
pattern = pattern:reverse()
if index >= 0 then
index = len - index + 1
else
index = index * -1
end
local s, e = text:find(pattern, index, true)
return e and len - e + 1, s and len - s + 1
end
local function rfind(text, pattern, index, plain) local function rfind(text, pattern, index, plain)
if plain then return plain_rfind(text, pattern, index) end local s, e = text:find(pattern, 1, plain)
local s, e = text:find(pattern)
local last_s, last_e local last_s, last_e
if index < 0 then index = #text - index + 1 end if index < 0 then index = #text - index + 1 end
while e and e <= index do while e and e <= index do
last_s, last_e = s, e last_s, last_e = s, e
s, e = text:find(pattern, s + 1) s, e = text:find(pattern, s + 1, plain)
end end
return last_s, last_e return last_s, last_e
end end