summaryrefslogtreecommitdiff
path: root/script/parser/guide.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-29 15:27:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-29 15:27:54 +0800
commit990596122167d4fa5bdc113f10d05027bb3a6bdf (patch)
tree9a55024db8e88e37ab4dd3e976e906b8e2b0c419 /script/parser/guide.lua
parentf832278c05667e2741946fc53d9fe580f52103bc (diff)
downloadlua-language-server-990596122167d4fa5bdc113f10d05027bb3a6bdf.zip
improve
Diffstat (limited to 'script/parser/guide.lua')
-rw-r--r--script/parser/guide.lua42
1 files changed, 23 insertions, 19 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 397447cb..82871d90 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -670,28 +670,32 @@ end
--- 遍历所有的source
function m.eachSource(ast, callback)
- local list = { ast }
- local mark = {}
- local index = 1
- while true do
- local obj = list[index]
- if not obj then
- return
- end
- list[index] = false
- index = index + 1
- if not mark[obj] then
- mark[obj] = true
- local res = callback(obj)
- if res == true then
- goto CONTINUE
- end
- if res == false then
+ local cache = ast.eachCache
+ if not cache then
+ cache = {}
+ ast.eachCache = cache
+ local list = { ast }
+ local mark = {}
+ local index = 1
+ while true do
+ local obj = list[index]
+ if not obj then
return
end
- m.addChilds(list, obj)
+ list[index] = false
+ cache[index] = obj
+ index = index + 1
+ if not mark[obj] then
+ mark[obj] = true
+ m.addChilds(list, obj)
+ end
+ end
+ end
+ for i = 1, #cache do
+ local res = callback(cache[i])
+ if res == false then
+ return
end
- ::CONTINUE::
end
end