mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Fix event table pool
This commit is contained in:
parent
dff522fbaa
commit
70e94ec14a
@ -32,7 +32,8 @@ function DruidEvent.subscribe(self, callback, context)
|
|||||||
assert(type(callback) == "function", "Callback should be function")
|
assert(type(callback) == "function", "Callback should be function")
|
||||||
|
|
||||||
self._callbacks = self._callbacks or tablepool.fetch(const.POOL_ID)
|
self._callbacks = self._callbacks or tablepool.fetch(const.POOL_ID)
|
||||||
local callback_table = tablepool.fetch(const.POOL_ID, 0, 2)
|
|
||||||
|
local callback_table = tablepool.fetch(const.POOL_ID)
|
||||||
callback_table.callback = callback
|
callback_table.callback = callback
|
||||||
callback_table.context = context
|
callback_table.context = context
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ function DruidEvent.unsubscribe(self, callback, context)
|
|||||||
|
|
||||||
for index, callback_info in ipairs(self._callbacks) do
|
for index, callback_info in ipairs(self._callbacks) do
|
||||||
if callback_info.callback == callback and callback_info.context == context then
|
if callback_info.callback == callback and callback_info.context == context then
|
||||||
tablepool.release(self._callbacks[index])
|
tablepool.release(const.POOL_ID, callback_info)
|
||||||
table.remove(self._callbacks, index)
|
table.remove(self._callbacks, index)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -75,12 +76,14 @@ end
|
|||||||
--- Clear the all event handlers
|
--- Clear the all event handlers
|
||||||
-- @tparam DruidEvent self @{DruidEvent}
|
-- @tparam DruidEvent self @{DruidEvent}
|
||||||
function DruidEvent.clear(self)
|
function DruidEvent.clear(self)
|
||||||
if self._callbacks then
|
if not self._callbacks then
|
||||||
for index = #self._callbacks, 1, -1 do
|
return
|
||||||
tablepool.release(self._callbacks[index])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
tablepool.release(self._callbacks)
|
|
||||||
|
for index = #self._callbacks, 1, -1 do
|
||||||
|
tablepool.release(const.POOL_ID, self._callbacks[index])
|
||||||
|
end
|
||||||
|
tablepool.release(const.POOL_ID, self._callbacks)
|
||||||
self._callbacks = nil
|
self._callbacks = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -252,6 +252,7 @@ function DruidInstance.final(self)
|
|||||||
local components = self.components_all
|
local components = self.components_all
|
||||||
|
|
||||||
for i = #components, 1, -1 do
|
for i = #components, 1, -1 do
|
||||||
|
components[i]:on_internal_remove()
|
||||||
if components[i].on_remove then
|
if components[i].on_remove then
|
||||||
components[i]:on_remove()
|
components[i]:on_remove()
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,6 @@ function _M.fetch(tag)
|
|||||||
pools[tag] = pool
|
pools[tag] = pool
|
||||||
pool.c = 0
|
pool.c = 0
|
||||||
pool[0] = 0
|
pool[0] = 0
|
||||||
|
|
||||||
else
|
else
|
||||||
local len = pool[0]
|
local len = pool[0]
|
||||||
if len > 0 then
|
if len > 0 then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user