Use string.find only in common.home_encode

Should be slightly more efficient.
This commit is contained in:
Francesco Abbate 2021-05-05 10:34:48 +02:00
parent d8244120e9
commit d63afe02ed
1 changed files with 4 additions and 4 deletions

View File

@ -204,10 +204,10 @@ end
function common.home_encode(text)
if HOME then
local n = #HOME
if text:sub(1, n) == HOME and text:sub(n + 1, n + 1):match("[/\\\\]") then
return "~" .. text:sub(n + 1)
if HOME and string.find(text, HOME, 1, true) == 1 then
local dir_pos = #HOME + 1
if string.find(text, PATHSEP, dir_pos, true) == dir_pos then
return "~" .. text:sub(dir_pos)
end
end
return text