From 990596122167d4fa5bdc113f10d05027bb3a6bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 29 Jul 2021 15:27:54 +0800 Subject: improve --- script/parser/guide.lua | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'script/parser/guide.lua') 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 -- cgit v1.2.3