From d63afe02edc150bd867387a82d276cfbb58223a5 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 5 May 2021 10:34:48 +0200 Subject: [PATCH] Use string.find only in common.home_encode Should be slightly more efficient. --- data/core/common.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data/core/common.lua b/data/core/common.lua index 7d67484b..022dd1dc 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -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