From c7611a41f655116b1526ead077686e7de6a2d9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 12 Mar 2019 10:31:01 +0800 Subject: =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/vm/value.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'server/src') diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index e6cbf876..d01712a6 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -22,6 +22,7 @@ local function create (tp, source, literal) source = source or getDefaultSource(), _type = {}, _literal = literal, + _info = {}, }, mt) if type(tp) == 'table' then for i = 1, #tp do @@ -200,7 +201,6 @@ function mt:eachChild(callback, mark, foundIndex) return method:eachChild(callback, mark, foundIndex) end -local hasSource = {} function mt:mergeValue(value) if value._type then for tp, rate in pairs(value._type) do @@ -216,17 +216,12 @@ function mt:mergeValue(value) self._child[k] = v end end - for _, info in ipairs(self) do - hasSource[info.source] = true - end - for _, info in ipairs(value) do - if not hasSource[info.source] then - self[#self+1] = info + for _, info in ipairs(value._info) do + if not self._info[info.source] then + self._info[#self._info+1] = info + self._info[info.source] = true end end - for k in pairs(hasSource) do - hasSource[k] = nil - end if value._meta then self._meta = value._meta end @@ -245,15 +240,20 @@ function mt:addInfo(tp, source, ...) if source and not source.start then error('Miss start: ' .. table.dump(source)) end - self[#self+1] = { + if self._info[source] then + return + end + local info = { type = tp, source = source or getDefaultSource(), ... } + self._info[#self._info+1] = info + self._info[info.source] = true end function mt:eachInfo(callback) - for _, info in ipairs(self) do + for _, info in ipairs(self._info) do local res = callback(info) if res ~= nil then return res -- cgit v1.2.3