summaryrefslogtreecommitdiff
path: root/script/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-05 21:23:38 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-05 21:23:38 +0800
commitb62eba6d93fc026873d29dc865cd3f745cb403fd (patch)
tree9ddb1bb78113f8201e634a2e3c305f4e0985d02f /script/parser
parenta6cfc1162c24e1621076bc96b36768873bbaf9d4 (diff)
downloadlua-language-server-b62eba6d93fc026873d29dc865cd3f745cb403fd.zip
improve performance
Diffstat (limited to 'script/parser')
-rw-r--r--script/parser/guide.lua8
-rw-r--r--script/parser/luadoc.lua77
2 files changed, 59 insertions, 26 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 6ba7e903..ab4cbdcd 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -2535,9 +2535,9 @@ function m.searchSameFields(status, simple, mode)
max = max + 1
status.share.count = status.share.count + 1
if status.share.count % 10000 == 0 then
- if TEST then
- print('####', status.share.count, osClock() - status.clock)
- end
+ --if TEST then
+ -- print('####', status.share.count, osClock() - status.clock)
+ --end
if status.interface and status.interface.pulse then
status.interface.pulse()
end
@@ -4212,7 +4212,7 @@ function m.requestReference(obj, interface, deep)
m.searchRefsAsFunction(status, obj, 'ref')
if m.debugMode then
- print('count:', status.share.count)
+ --print('count:', status.share.count)
end
return status.results, status.share.count
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 647a6bed..832cdc87 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -992,28 +992,43 @@ local function bindGeneric(binded)
end
end
-local function bindDocsBetween(state, binded, bindSources, start, finish)
- guide.eachSourceBetween(state.ast, start, finish, function (src)
- if src.start and src.start < start then
- return
+local function bindDocsBetween(sources, binded, bindSources, start, finish)
+ -- 用二分法找到第一个
+ local max = #sources
+ local index
+ local left = 1
+ local right = max
+ for _ = 1, 1000 do
+ index = left + (right - left) // 2
+ if index <= left then
+ index = left
+ break
+ elseif index >= right then
+ index = right
+ break
end
- if src.type == 'local'
- or src.type == 'setlocal'
- or src.type == 'setglobal'
- or src.type == 'setfield'
- or src.type == 'setmethod'
- or src.type == 'setindex'
- or src.type == 'tablefield'
- or src.type == 'tableindex'
- or src.type == 'function'
- or src.type == '...' then
- src.bindDocs = binded
- bindSources[#bindSources+1] = src
+ local src = sources[index]
+ if src.start < start then
+ left = index
+ else
+ right = index
end
- end)
+ end
+ for i = index - 1, max do
+ local src = sources[i]
+ if src then
+ if src.start > finish then
+ break
+ end
+ if src.start >= start then
+ src.bindDocs = binded
+ bindSources[#bindSources+1] = src
+ end
+ end
+ end
end
-local function bindDoc(state, lns, binded)
+local function bindDoc(sources, lns, binded)
if not binded then
return
end
@@ -1030,24 +1045,42 @@ local function bindDoc(state, lns, binded)
local row = guide.positionOf(lns, lastDoc.finish)
local cstart, cfinish = guide.lineRange(lns, row)
local nstart, nfinish = guide.lineRange(lns, row + 1)
- bindDocsBetween(state, binded, bindSources, cstart, cfinish)
+ bindDocsBetween(sources, binded, bindSources, cstart, cfinish)
if #bindSources == 0 then
- bindDocsBetween(state, binded, bindSources, nstart, nfinish)
+ bindDocsBetween(sources, binded, bindSources, nstart, nfinish)
end
end
local function bindDocs(state)
local lns = lines(nil, state.lua)
+ local sources = {}
+ guide.eachSource(state.ast, function (src)
+ if src.type == 'local'
+ or src.type == 'setlocal'
+ or src.type == 'setglobal'
+ or src.type == 'setfield'
+ or src.type == 'setmethod'
+ or src.type == 'setindex'
+ or src.type == 'tablefield'
+ or src.type == 'tableindex'
+ or src.type == 'function'
+ or src.type == '...' then
+ sources[#sources+1] = src
+ end
+ end)
+ table.sort(sources, function (a, b)
+ return a.start < b.start
+ end)
local binded
for _, doc in ipairs(state.ast.docs) do
if not isNextLine(lns, binded, doc) then
- bindDoc(state, lns, binded)
+ bindDoc(sources, lns, binded)
binded = {}
state.ast.docs.groups[#state.ast.docs.groups+1] = binded
end
binded[#binded+1] = doc
end
- bindDoc(state, lns, binded)
+ bindDoc(sources, lns, binded)
end
return function (_, state)