mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Revert "Solve #182 add table pool for events"
This reverts commit dff522fbaa8775ed983f6a2b83409addef7d112d.
This commit is contained in:
parent
70e94ec14a
commit
f7e6888c5a
@ -30,12 +30,6 @@ function BackHandler.init(self, callback, params)
|
||||
end
|
||||
|
||||
|
||||
function BackHandler.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_back:clear()
|
||||
end
|
||||
|
||||
|
||||
--- Input handler for component
|
||||
-- @tparam BackHandler self @{BackHandler}
|
||||
-- @tparam string action_id on_input action id
|
||||
|
@ -239,17 +239,6 @@ function Button.on_late_init(self)
|
||||
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)
|
||||
if not is_input_match(self, action_id) then
|
||||
return false
|
||||
|
@ -189,16 +189,6 @@ function Drag.init(self, node, on_drag_callback)
|
||||
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)
|
||||
if not self.click_zone and const.IS_STENCIL_CHECK then
|
||||
local stencil_node = helper.get_closest_stencil_node(self.node)
|
||||
|
@ -38,13 +38,6 @@ function Hover.init(self, node, on_hover_callback)
|
||||
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)
|
||||
if not self.click_zone and const.IS_STENCIL_CHECK then
|
||||
local stencil_node = helper.get_closest_stencil_node(self.node)
|
||||
|
@ -174,14 +174,6 @@ function Scroll.init(self, view_node, content_node)
|
||||
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)
|
||||
if not self.click_zone and const.IS_STENCIL_CHECK then
|
||||
local stencil_node = helper.get_closest_stencil_node(self.node)
|
||||
|
@ -115,16 +115,6 @@ function StaticGrid.init(self, parent, element, in_row)
|
||||
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)
|
||||
--- Return pos for grid node index
|
||||
-- @tparam StaticGrid self @{StaticGrid}
|
||||
|
@ -99,12 +99,6 @@ function Swipe.init(self, node, on_swipe_callback)
|
||||
end
|
||||
|
||||
|
||||
function Swipe.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_swipe:clear()
|
||||
end
|
||||
|
||||
|
||||
function Swipe.on_late_init(self)
|
||||
if not self.click_zone and const.IS_STENCIL_CHECK then
|
||||
local stencil_node = helper.get_closest_stencil_node(self.node)
|
||||
|
@ -217,14 +217,6 @@ function Text.init(self, node, value, adjust_type)
|
||||
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)
|
||||
self:set_to(self.last_value)
|
||||
end
|
||||
|
@ -8,7 +8,6 @@
|
||||
local const = require("druid.const")
|
||||
local class = require("druid.system.middleclass")
|
||||
local helper = require("druid.helper")
|
||||
local tablepool = require("druid.system.tablepool")
|
||||
|
||||
|
||||
local BaseComponent = class("druid.component")
|
||||
@ -349,11 +348,6 @@ function BaseComponent.set_debug(self, is_debug)
|
||||
end
|
||||
|
||||
|
||||
--- On remove method on druid:remove or druid:final (protected)
|
||||
function BaseComponent:on_internal_remove()
|
||||
end
|
||||
|
||||
|
||||
--- Return true, if input priority was changed
|
||||
-- @tparam BaseComponent self @{BaseComponent}
|
||||
-- @local
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
M.POOL_ID = "druid_table_pool"
|
||||
|
||||
M.ACTION_TEXT = hash(sys.get_config("druid.input_text", "text"))
|
||||
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"))
|
||||
|
@ -5,8 +5,6 @@
|
||||
-- @alias druid.event
|
||||
|
||||
local class = require("druid.system.middleclass")
|
||||
local const = require("druid.const")
|
||||
local tablepool = require("druid.system.tablepool")
|
||||
|
||||
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(callback) == "function", "Callback should be function")
|
||||
|
||||
self._callbacks = self._callbacks or tablepool.fetch(const.POOL_ID)
|
||||
|
||||
local callback_table = tablepool.fetch(const.POOL_ID)
|
||||
callback_table.callback = callback
|
||||
callback_table.context = context
|
||||
|
||||
table.insert(self._callbacks, callback_table)
|
||||
self._callbacks = self._callbacks or {}
|
||||
table.insert(self._callbacks, {
|
||||
callback = callback,
|
||||
context = context
|
||||
})
|
||||
|
||||
return callback
|
||||
end
|
||||
@ -54,7 +50,6 @@ function DruidEvent.unsubscribe(self, callback, context)
|
||||
|
||||
for index, callback_info in ipairs(self._callbacks) do
|
||||
if callback_info.callback == callback and callback_info.context == context then
|
||||
tablepool.release(const.POOL_ID, callback_info)
|
||||
table.remove(self._callbacks, index)
|
||||
return
|
||||
end
|
||||
@ -76,14 +71,6 @@ end
|
||||
--- Clear the all event handlers
|
||||
-- @tparam DruidEvent self @{DruidEvent}
|
||||
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
|
||||
end
|
||||
|
||||
@ -96,7 +83,7 @@ function DruidEvent.trigger(self, ...)
|
||||
return false
|
||||
end
|
||||
|
||||
for _, callback_info in ipairs(self._callbacks) do
|
||||
for index, callback_info in ipairs(self._callbacks) do
|
||||
if callback_info.context then
|
||||
callback_info.callback(callback_info.context, ...)
|
||||
else
|
||||
|
@ -67,12 +67,6 @@ function Checkbox.on_layout_change(self)
|
||||
end
|
||||
|
||||
|
||||
function Checkbox.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_change_state:clear()
|
||||
end
|
||||
|
||||
|
||||
--- Set checkbox state
|
||||
-- @tparam Checkbox self @{Checkbox}
|
||||
-- @tparam bool state Checkbox state
|
||||
|
@ -41,13 +41,6 @@ function CheckboxGroup.init(self, nodes, callback, click_nodes)
|
||||
end
|
||||
|
||||
|
||||
function CheckboxGroup.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_checkbox_click:clear()
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Set checkbox group state
|
||||
-- @tparam CheckboxGroup self @{CheckboxGroup}
|
||||
-- @tparam bool[] indexes Array of checkbox state
|
||||
|
@ -76,12 +76,6 @@ function DataList.on_remove(self)
|
||||
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
|
||||
-- @tparam DataList self @{DataList}
|
||||
-- @tparam table data The new data array
|
||||
|
@ -89,16 +89,6 @@ function DynamicGrid.init(self, parent)
|
||||
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)
|
||||
self:_update(true)
|
||||
end
|
||||
|
@ -154,17 +154,6 @@ function Input.init(self, click_node, text_node, keyboard_type)
|
||||
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)
|
||||
if self.is_selected then
|
||||
local input_text = nil
|
||||
|
@ -41,12 +41,6 @@ function LangText.init(self, node, locale_id, no_adjust)
|
||||
end
|
||||
|
||||
|
||||
function LangText.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_change:clear()
|
||||
end
|
||||
|
||||
|
||||
function LangText.on_language_change(self)
|
||||
if self.last_locale then
|
||||
self:translate(self.last_locale, unpack(self.last_locale_args))
|
||||
|
@ -39,12 +39,6 @@ function Layout:init(node, mode, on_size_changed_callback)
|
||||
end
|
||||
|
||||
|
||||
function Layout.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_size_changed:clear()
|
||||
end
|
||||
|
||||
|
||||
function Layout:on_window_resized()
|
||||
local window_x, window_y = window.get_size()
|
||||
local stretch_x = window_x / self.window_size.x
|
||||
|
@ -121,12 +121,6 @@ function Progress.init(self, node, key, init_value)
|
||||
end
|
||||
|
||||
|
||||
function Progress.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_change:clear()
|
||||
end
|
||||
|
||||
|
||||
-- @tparam Progress self @{Progress}
|
||||
function Progress.on_late_init(self)
|
||||
self:set_to(self._init_value)
|
||||
|
@ -50,12 +50,6 @@ function RadioGroup.init(self, nodes, callback, click_nodes)
|
||||
end
|
||||
|
||||
|
||||
function RadioGroup.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_radio_click:clear()
|
||||
end
|
||||
|
||||
|
||||
--- Set radio group state
|
||||
-- @tparam RadioGroup self @{RadioGroup}
|
||||
-- @tparam number index Index in radio group
|
||||
|
@ -77,12 +77,6 @@ function Slider.init(self, node, end_pos, callback)
|
||||
end
|
||||
|
||||
|
||||
function Slider.on_internal_remove(self)
|
||||
component.on_internal_remove(self)
|
||||
self.on_change_value:clear()
|
||||
end
|
||||
|
||||
|
||||
function Slider.on_layout_change(self)
|
||||
self:set(self.value)
|
||||
end
|
||||
|
@ -65,14 +65,6 @@ function Timer.init(self, node, seconds_from, seconds_to, callback)
|
||||
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)
|
||||
if not self.is_on then
|
||||
return
|
||||
|
@ -252,7 +252,6 @@ function DruidInstance.final(self)
|
||||
local components = self.components_all
|
||||
|
||||
for i = #components, 1, -1 do
|
||||
components[i]:on_internal_remove()
|
||||
if components[i].on_remove then
|
||||
components[i]:on_remove()
|
||||
end
|
||||
@ -290,7 +289,6 @@ function DruidInstance.remove(self, component)
|
||||
local all_components = self.components_all
|
||||
for i = #all_components, 1, -1 do
|
||||
if all_components[i] == component then
|
||||
component:on_internal_remove()
|
||||
if component.on_remove then
|
||||
component:on_remove()
|
||||
end
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user