summaryrefslogtreecommitdiff
path: root/script/parser/guide.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-28 14:26:07 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-28 14:26:07 +0800
commitf9cf323b0e0de084c74c243432d02ec1598cc6dc (patch)
tree8185f0822bcb1f7ed59d48336c9afba63acb989c /script/parser/guide.lua
parent00ee999bf2c82b23c8103dffe1e43910a358c89f (diff)
downloadlua-language-server-f9cf323b0e0de084c74c243432d02ec1598cc6dc.zip
optimize performance
Diffstat (limited to 'script/parser/guide.lua')
-rw-r--r--script/parser/guide.lua31
1 files changed, 27 insertions, 4 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index b9d904f3..f6f9d7c6 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -2367,10 +2367,32 @@ function m.checkSameSimple(status, simple, ref, start, force, mode, pushQueue)
end
end
+local queuesPool = {}
+local startsPool = {}
+local forcesPool = {}
+local poolSize = 0
+
+local function allocQueue()
+ if poolSize <= 0 then
+ return {}, {}, {}
+ else
+ local queues = queuesPool[poolSize]
+ local starts = startsPool[poolSize]
+ local forces = forcesPool[poolSize]
+ poolSize = poolSize - 1
+ return queues, starts, forces
+ end
+end
+
+local function deallocQueue(queues, starts, forces)
+ poolSize = poolSize + 1
+ queuesPool[poolSize] = queues
+ startsPool[poolSize] = starts
+ forcesPool[poolSize] = forces
+end
+
function m.searchSameFields(status, simple, mode)
- local queues = {}
- local starts = {}
- local forces = {}
+ local queues, starts, forces = allocQueue()
local queueLen = 0
local function pushQueue(obj, start, force)
queueLen = queueLen + 1
@@ -2397,7 +2419,7 @@ function m.searchSameFields(status, simple, mode)
local locks = {}
for i = 1, 1e6 do
if queueLen <= 0 then
- return
+ break
end
local obj = queues[queueLen]
local start = starts[queueLen]
@@ -2419,6 +2441,7 @@ function m.searchSameFields(status, simple, mode)
end
end
end
+ deallocQueue(queues, starts, forces)
end
function m.getCallerInSameFile(status, func)