Revert "Solve #182 add table pool for events"

This reverts commit dff522fbaa8775ed983f6a2b83409addef7d112d.
This commit is contained in:
Insality 2022-04-05 23:18:39 +03:00
parent 70e94ec14a
commit f7e6888c5a
24 changed files with 6 additions and 247 deletions

View File

@ -30,12 +30,6 @@ function BackHandler.init(self, callback, params)
end end
function BackHandler.on_internal_remove(self)
component.on_internal_remove(self)
self.on_back:clear()
end
--- Input handler for component --- Input handler for component
-- @tparam BackHandler self @{BackHandler} -- @tparam BackHandler self @{BackHandler}
-- @tparam string action_id on_input action id -- @tparam string action_id on_input action id

View File

@ -239,17 +239,6 @@ function Button.on_late_init(self)
end end
function Button.on_internal_remove(self)
component.on_internal_remove(self)
self.on_click:clear()
self.on_repeated_click:clear()
self.on_long_click:clear()
self.on_double_click:clear()
self.on_hold_callback:clear()
self.on_click_outside:clear()
end
function Button.on_input(self, action_id, action) function Button.on_input(self, action_id, action)
if not is_input_match(self, action_id) then if not is_input_match(self, action_id) then
return false return false

View File

@ -189,16 +189,6 @@ function Drag.init(self, node, on_drag_callback)
end end
function Drag.on_internal_remove(self)
component.on_internal_remove(self)
self.on_touch_start:clear()
self.on_touch_end:clear()
self.on_drag_start:clear()
self.on_drag:clear()
self.on_drag_end:clear()
end
function Drag.on_late_init(self) function Drag.on_late_init(self)
if not self.click_zone and const.IS_STENCIL_CHECK then if not self.click_zone and const.IS_STENCIL_CHECK then
local stencil_node = helper.get_closest_stencil_node(self.node) local stencil_node = helper.get_closest_stencil_node(self.node)

View File

@ -38,13 +38,6 @@ function Hover.init(self, node, on_hover_callback)
end end
function Hover.on_internal_remove(self)
component.on_internal_remove(self)
self.on_hover:clear()
self.on_mouse_hover:clear()
end
function Hover.on_late_init(self) function Hover.on_late_init(self)
if not self.click_zone and const.IS_STENCIL_CHECK then if not self.click_zone and const.IS_STENCIL_CHECK then
local stencil_node = helper.get_closest_stencil_node(self.node) local stencil_node = helper.get_closest_stencil_node(self.node)

View File

@ -174,14 +174,6 @@ function Scroll.init(self, view_node, content_node)
end end
function Scroll.on_internal_remove(self)
component.on_internal_remove(self)
self.on_scroll:clear()
self.on_scroll_to:clear()
self.on_point_scroll:clear()
end
function Scroll.on_late_init(self) function Scroll.on_late_init(self)
if not self.click_zone and const.IS_STENCIL_CHECK then if not self.click_zone and const.IS_STENCIL_CHECK then
local stencil_node = helper.get_closest_stencil_node(self.node) local stencil_node = helper.get_closest_stencil_node(self.node)

View File

@ -115,16 +115,6 @@ function StaticGrid.init(self, parent, element, in_row)
end end
function StaticGrid.on_internal_remove(self)
component.on_internal_remove(self)
self.on_add_item:clear()
self.on_remove_item:clear()
self.on_change_items:clear()
self.on_clear:clear()
self.on_update_positions:clear()
end
local _temp_pos = vmath.vector3(0) local _temp_pos = vmath.vector3(0)
--- Return pos for grid node index --- Return pos for grid node index
-- @tparam StaticGrid self @{StaticGrid} -- @tparam StaticGrid self @{StaticGrid}

View File

@ -99,12 +99,6 @@ function Swipe.init(self, node, on_swipe_callback)
end end
function Swipe.on_internal_remove(self)
component.on_internal_remove(self)
self.on_swipe:clear()
end
function Swipe.on_late_init(self) function Swipe.on_late_init(self)
if not self.click_zone and const.IS_STENCIL_CHECK then if not self.click_zone and const.IS_STENCIL_CHECK then
local stencil_node = helper.get_closest_stencil_node(self.node) local stencil_node = helper.get_closest_stencil_node(self.node)

View File

@ -217,14 +217,6 @@ function Text.init(self, node, value, adjust_type)
end end
function Text.on_internal_remove(self)
component.on_internal_remove(self)
self.on_set_text:clear()
self.on_set_pivot:clear()
self.on_update_text_scale:clear()
end
function Text.on_layout_change(self) function Text.on_layout_change(self)
self:set_to(self.last_value) self:set_to(self.last_value)
end end

View File

@ -8,7 +8,6 @@
local const = require("druid.const") local const = require("druid.const")
local class = require("druid.system.middleclass") local class = require("druid.system.middleclass")
local helper = require("druid.helper") local helper = require("druid.helper")
local tablepool = require("druid.system.tablepool")
local BaseComponent = class("druid.component") local BaseComponent = class("druid.component")
@ -349,11 +348,6 @@ function BaseComponent.set_debug(self, is_debug)
end end
--- On remove method on druid:remove or druid:final (protected)
function BaseComponent:on_internal_remove()
end
--- Return true, if input priority was changed --- Return true, if input priority was changed
-- @tparam BaseComponent self @{BaseComponent} -- @tparam BaseComponent self @{BaseComponent}
-- @local -- @local

View File

@ -7,8 +7,6 @@
local M = {} local M = {}
M.POOL_ID = "druid_table_pool"
M.ACTION_TEXT = hash(sys.get_config("druid.input_text", "text")) M.ACTION_TEXT = hash(sys.get_config("druid.input_text", "text"))
M.ACTION_TOUCH = hash(sys.get_config("druid.input_touch", "touch")) M.ACTION_TOUCH = hash(sys.get_config("druid.input_touch", "touch"))
M.ACTION_MARKED_TEXT = hash(sys.get_config("druid.input_marked_text", "marked_text")) M.ACTION_MARKED_TEXT = hash(sys.get_config("druid.input_marked_text", "marked_text"))

View File

@ -5,8 +5,6 @@
-- @alias druid.event -- @alias druid.event
local class = require("druid.system.middleclass") local class = require("druid.system.middleclass")
local const = require("druid.const")
local tablepool = require("druid.system.tablepool")
local DruidEvent = class("druid.event") local DruidEvent = class("druid.event")
@ -31,13 +29,11 @@ function DruidEvent.subscribe(self, callback, context)
assert(type(self) == "table", "You should subscribe to event with : syntax") assert(type(self) == "table", "You should subscribe to event with : syntax")
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 {}
table.insert(self._callbacks, {
local callback_table = tablepool.fetch(const.POOL_ID) callback = callback,
callback_table.callback = callback context = context
callback_table.context = context })
table.insert(self._callbacks, callback_table)
return callback return callback
end end
@ -54,7 +50,6 @@ 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(const.POOL_ID, callback_info)
table.remove(self._callbacks, index) table.remove(self._callbacks, index)
return return
end end
@ -76,14 +71,6 @@ 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 not self._callbacks then
return
end
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
@ -96,7 +83,7 @@ function DruidEvent.trigger(self, ...)
return false return false
end end
for _, callback_info in ipairs(self._callbacks) do for index, callback_info in ipairs(self._callbacks) do
if callback_info.context then if callback_info.context then
callback_info.callback(callback_info.context, ...) callback_info.callback(callback_info.context, ...)
else else

View File

@ -67,12 +67,6 @@ function Checkbox.on_layout_change(self)
end end
function Checkbox.on_internal_remove(self)
component.on_internal_remove(self)
self.on_change_state:clear()
end
--- Set checkbox state --- Set checkbox state
-- @tparam Checkbox self @{Checkbox} -- @tparam Checkbox self @{Checkbox}
-- @tparam bool state Checkbox state -- @tparam bool state Checkbox state

View File

@ -41,13 +41,6 @@ function CheckboxGroup.init(self, nodes, callback, click_nodes)
end end
function CheckboxGroup.on_internal_remove(self)
component.on_internal_remove(self)
self.on_checkbox_click:clear()
end
--- Set checkbox group state --- Set checkbox group state
-- @tparam CheckboxGroup self @{CheckboxGroup} -- @tparam CheckboxGroup self @{CheckboxGroup}
-- @tparam bool[] indexes Array of checkbox state -- @tparam bool[] indexes Array of checkbox state

View File

@ -76,12 +76,6 @@ function DataList.on_remove(self)
end end
function DataList.on_internal_remove(self)
component.on_internal_remove(self)
self.on_scroll_progress_change:clear()
end
--- Set new data set for DataList component --- Set new data set for DataList component
-- @tparam DataList self @{DataList} -- @tparam DataList self @{DataList}
-- @tparam table data The new data array -- @tparam table data The new data array

View File

@ -89,16 +89,6 @@ function DynamicGrid.init(self, parent)
end end
function DynamicGrid.on_internal_remove(self)
component.on_internal_remove(self)
self.on_add_item:clear()
self.on_remove_item:clear()
self.on_change_items:clear()
self.on_clear:clear()
self.on_update_positions:clear()
end
function DynamicGrid.on_layout_change(self) function DynamicGrid.on_layout_change(self)
self:_update(true) self:_update(true)
end end

View File

@ -154,17 +154,6 @@ function Input.init(self, click_node, text_node, keyboard_type)
end end
function Input.on_internal_remove(self)
component.on_internal_remove(self)
self.on_input_select:clear()
self.on_input_unselect:clear()
self.on_input_text:clear()
self.on_input_empty:clear()
self.on_input_full:clear()
self.on_input_wrong:clear()
end
function Input.on_input(self, action_id, action) function Input.on_input(self, action_id, action)
if self.is_selected then if self.is_selected then
local input_text = nil local input_text = nil

View File

@ -41,12 +41,6 @@ function LangText.init(self, node, locale_id, no_adjust)
end end
function LangText.on_internal_remove(self)
component.on_internal_remove(self)
self.on_change:clear()
end
function LangText.on_language_change(self) function LangText.on_language_change(self)
if self.last_locale then if self.last_locale then
self:translate(self.last_locale, unpack(self.last_locale_args)) self:translate(self.last_locale, unpack(self.last_locale_args))

View File

@ -39,12 +39,6 @@ function Layout:init(node, mode, on_size_changed_callback)
end end
function Layout.on_internal_remove(self)
component.on_internal_remove(self)
self.on_size_changed:clear()
end
function Layout:on_window_resized() function Layout:on_window_resized()
local window_x, window_y = window.get_size() local window_x, window_y = window.get_size()
local stretch_x = window_x / self.window_size.x local stretch_x = window_x / self.window_size.x

View File

@ -121,12 +121,6 @@ function Progress.init(self, node, key, init_value)
end end
function Progress.on_internal_remove(self)
component.on_internal_remove(self)
self.on_change:clear()
end
-- @tparam Progress self @{Progress} -- @tparam Progress self @{Progress}
function Progress.on_late_init(self) function Progress.on_late_init(self)
self:set_to(self._init_value) self:set_to(self._init_value)

View File

@ -50,12 +50,6 @@ function RadioGroup.init(self, nodes, callback, click_nodes)
end end
function RadioGroup.on_internal_remove(self)
component.on_internal_remove(self)
self.on_radio_click:clear()
end
--- Set radio group state --- Set radio group state
-- @tparam RadioGroup self @{RadioGroup} -- @tparam RadioGroup self @{RadioGroup}
-- @tparam number index Index in radio group -- @tparam number index Index in radio group

View File

@ -77,12 +77,6 @@ function Slider.init(self, node, end_pos, callback)
end end
function Slider.on_internal_remove(self)
component.on_internal_remove(self)
self.on_change_value:clear()
end
function Slider.on_layout_change(self) function Slider.on_layout_change(self)
self:set(self.value) self:set(self.value)
end end

View File

@ -65,14 +65,6 @@ function Timer.init(self, node, seconds_from, seconds_to, callback)
end end
function Timer.on_internal_remove(self)
component.on_internal_remove(self)
self.on_tick:clear()
self.on_set_enabled:clear()
self.on_timer_end:clear()
end
function Timer.update(self, dt) function Timer.update(self, dt)
if not self.is_on then if not self.is_on then
return return

View File

@ -252,7 +252,6 @@ 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
@ -290,7 +289,6 @@ function DruidInstance.remove(self, component)
local all_components = self.components_all local all_components = self.components_all
for i = #all_components, 1, -1 do for i = #all_components, 1, -1 do
if all_components[i] == component then if all_components[i] == component then
component:on_internal_remove()
if component.on_remove then if component.on_remove then
component:on_remove() component:on_remove()
end end

View File

@ -1,74 +0,0 @@
-- Source: https://github.com/openresty/lua-tablepool/blob/master/lib/tablepool.lua
local setmetatable = setmetatable
local _M = {}
local max_pool_size = 500
local pools = {}
function _M.fetch(tag)
local pool = pools[tag]
if not pool then
pool = {}
pools[tag] = pool
pool.c = 0
pool[0] = 0
else
local len = pool[0]
if len > 0 then
local obj = pool[len]
pool[len] = nil
pool[0] = len - 1
return obj
end
end
return {}
end
function _M.release(tag, obj, noclear)
if not obj then
error("object empty", 2)
end
local pool = pools[tag]
if not pool then
pool = {}
pools[tag] = pool
pool.c = 0
pool[0] = 0
end
if not noclear then
setmetatable(obj, nil)
for k in pairs(obj) do
obj[k] = nil
end
end
do
local cnt = pool.c + 1
if cnt >= 20000 then
pool = {}
pools[tag] = pool
pool.c = 0
pool[0] = 0
return
end
pool.c = cnt
end
local len = pool[0] + 1
if len > max_pool_size then
-- discard it simply
return
end
pool[len] = obj
pool[0] = len
end
return _M