Skip to content

Commit 37b5f6c

Browse files
committed
improve performance
1 parent 3a0596e commit 37b5f6c

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

script/workspace/require-path.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ local function getOnePath(uri, path, searcher)
2828
: gsub('%.[^%.]+$', '')
2929
: gsub('[/\\%.]+', separator)
3030
local start = stemSearcher:match '()%?' or 1
31-
for pos = start, #stemPath do
31+
if stemPath:sub(1, start - 1) ~= stemSearcher:sub(1, start - 1) then
32+
return nil
33+
end
34+
for pos = #stemPath, start, -1 do
3235
local word = stemPath:sub(start, pos)
3336
local newSearcher = stemSearcher:gsub('%?', (word:gsub('%%', '%%%%')))
3437
if newSearcher == stemPath then
@@ -43,8 +46,12 @@ function m.getVisiblePath(suri, path)
4346
local strict = config.get(suri, 'Lua.runtime.pathStrict')
4447
path = workspace.normalize(path)
4548
local uri = furi.encode(path)
46-
local libraryPath = furi.decode(files.getLibraryUri(suri, uri))
4749
local scp = scope.getScope(suri)
50+
if not scp:isChildUri(uri)
51+
and not scp:isLinkedUri(uri) then
52+
return {}
53+
end
54+
local libraryPath = furi.decode(files.getLibraryUri(suri, uri))
4855
local cache = scp:get('visiblePath') or scp:set('visiblePath', {})
4956
local result = cache[path]
5057
if not result then
@@ -62,9 +69,13 @@ function m.getVisiblePath(suri, path)
6269
local pos = 1
6370
if not isAbsolute then
6471
if libraryPath then
65-
pos = #libraryPath + 2
72+
currentPath = currentPath:sub(#libraryPath + 2)
6673
else
67-
currentPath = workspace.getRelativePath(uri)
74+
local isRelative
75+
currentPath, isRelative = workspace.getRelativePath(uri)
76+
if not isAbsolute and not isRelative then
77+
goto CONTINUE
78+
end
6879
end
6980
end
7081
repeat
@@ -89,6 +100,7 @@ function m.getVisiblePath(suri, path)
89100
addRequireName(suri, uri, expect)
90101
end
91102
until not pos or strict
103+
::CONTINUE::
92104
end
93105
end
94106
return result

script/workspace/workspace.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,13 @@ function m.getRelativePath(uriOrPath)
372372
local scp = scope.getScope(uri)
373373
if not scp.uri then
374374
local relative = m.normalize(path)
375-
return relative:gsub('^[/\\]+', '')
375+
return relative:gsub('^[/\\]+', ''), false
376376
end
377377
local _, pos = m.normalize(path):find(furi.decode(scp.uri), 1, true)
378378
if pos then
379-
return m.normalize(path:sub(pos + 1)):gsub('^[/\\]+', '')
379+
return m.normalize(path:sub(pos + 1)):gsub('^[/\\]+', ''), true
380380
else
381-
return m.normalize(path):gsub('^[/\\]+', '')
381+
return m.normalize(path):gsub('^[/\\]+', ''), false
382382
end
383383
end
384384

0 commit comments

Comments
 (0)