opt: removing without removed_sets

This commit is contained in:
BlackMATov
2025-05-15 04:41:41 +07:00
parent f19b1b5d14
commit 0f1012ee41
2 changed files with 23 additions and 27 deletions

View File

@@ -498,42 +498,44 @@ do
local e = evo.id()
local remove_count = 0
local last_removed_component = nil
local removed_sum = 0
evo.set(f1, evo.ON_REMOVE, function(entity, fragment, component)
assert(entity == e)
assert(fragment == f1)
remove_count = remove_count + 1
last_removed_component = component
removed_sum = removed_sum + component
end)
evo.set(f2, evo.ON_REMOVE, function(entity, fragment, component)
assert(entity == e)
assert(fragment == f2)
remove_count = remove_count + 1
last_removed_component = component
removed_sum = removed_sum + component
end)
evo.set(e, f1, 42)
evo.remove(e, f1, f2)
assert(remove_count == 1)
assert(last_removed_component == 42)
assert(removed_sum == 42)
evo.set(e, f1, 42)
evo.set(e, f2, 43)
evo.remove(e, f1, f2, f2)
assert(remove_count == 3)
assert(last_removed_component == 43)
assert(removed_sum == 42 + 42 + 43)
evo.set(e, f1, 44)
evo.set(e, f2, 45)
evo.clear(e)
assert(remove_count == 5)
assert(removed_sum == 42 + 42 + 43 + 44 + 45)
evo.set(e, f1, 46)
evo.set(e, f2, 47)
evo.destroy(e)
assert(remove_count == 7)
assert(removed_sum == 42 + 42 + 43 + 44 + 45 + 46 + 47)
end
do

View File

@@ -2544,21 +2544,20 @@ function __chunk_remove(old_chunk, ...)
return
end
local old_fragment_set = old_chunk.__fragment_set
local old_fragment_list = old_chunk.__fragment_list
local old_fragment_count = old_chunk.__fragment_count
local old_component_indices = old_chunk.__component_indices
local old_component_storages = old_chunk.__component_storages
if old_chunk.__has_remove_hooks then
---@type table<evolved.fragment, boolean>
local removed_set = __acquire_table(__table_pool_tag.fragment_set)
---@type table<evolved.fragment, integer>
local new_fragment_set = new_chunk and new_chunk.__fragment_set
or __safe_tbls.__EMPTY_FRAGMENT_SET
for i = 1, fragment_count do
---@type evolved.fragment
local fragment = __lua_select(i, ...)
if not removed_set[fragment] and old_fragment_set[fragment] then
removed_set[fragment] = true
for i = 1, old_fragment_count do
local fragment = old_fragment_list[i]
if not new_fragment_set[fragment] then
---@type evolved.remove_hook?
local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE)
@@ -2582,8 +2581,6 @@ function __chunk_remove(old_chunk, ...)
end
end
end
__release_table(__table_pool_tag.fragment_set, removed_set)
end
if new_chunk then
@@ -3990,21 +3987,20 @@ function __evolved_remove(entity, ...)
__evolved_defer()
do
local old_fragment_set = old_chunk.__fragment_set
local old_fragment_list = old_chunk.__fragment_list
local old_fragment_count = old_chunk.__fragment_count
local old_component_indices = old_chunk.__component_indices
local old_component_storages = old_chunk.__component_storages
if old_chunk.__has_remove_hooks then
---@type table<evolved.fragment, boolean>
local removed_set = __acquire_table(__table_pool_tag.fragment_set)
---@type table<evolved.fragment, integer>
local new_fragment_set = new_chunk and new_chunk.__fragment_set
or __safe_tbls.__EMPTY_FRAGMENT_SET
for i = 1, fragment_count do
---@type evolved.fragment
local fragment = __lua_select(i, ...)
if not removed_set[fragment] and old_fragment_set[fragment] then
removed_set[fragment] = true
for i = 1, old_fragment_count do
local fragment = old_fragment_list[i]
if not new_fragment_set[fragment] then
---@type evolved.remove_hook?
local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE)
@@ -4021,8 +4017,6 @@ function __evolved_remove(entity, ...)
end
end
end
__release_table(__table_pool_tag.fragment_set, removed_set)
end
if new_chunk then