Skip to content

Commit 0f1012e

Browse files
committed
opt: removing without removed_sets
1 parent f19b1b5 commit 0f1012e

2 files changed

Lines changed: 23 additions & 27 deletions

File tree

develop/untests.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,42 +498,44 @@ do
498498
local e = evo.id()
499499

500500
local remove_count = 0
501-
local last_removed_component = nil
501+
local removed_sum = 0
502502

503503
evo.set(f1, evo.ON_REMOVE, function(entity, fragment, component)
504504
assert(entity == e)
505505
assert(fragment == f1)
506506
remove_count = remove_count + 1
507-
last_removed_component = component
507+
removed_sum = removed_sum + component
508508
end)
509509

510510
evo.set(f2, evo.ON_REMOVE, function(entity, fragment, component)
511511
assert(entity == e)
512512
assert(fragment == f2)
513513
remove_count = remove_count + 1
514-
last_removed_component = component
514+
removed_sum = removed_sum + component
515515
end)
516516

517517
evo.set(e, f1, 42)
518518
evo.remove(e, f1, f2)
519519
assert(remove_count == 1)
520-
assert(last_removed_component == 42)
520+
assert(removed_sum == 42)
521521

522522
evo.set(e, f1, 42)
523523
evo.set(e, f2, 43)
524524
evo.remove(e, f1, f2, f2)
525525
assert(remove_count == 3)
526-
assert(last_removed_component == 43)
526+
assert(removed_sum == 42 + 42 + 43)
527527

528528
evo.set(e, f1, 44)
529529
evo.set(e, f2, 45)
530530
evo.clear(e)
531531
assert(remove_count == 5)
532+
assert(removed_sum == 42 + 42 + 43 + 44 + 45)
532533

533534
evo.set(e, f1, 46)
534535
evo.set(e, f2, 47)
535536
evo.destroy(e)
536537
assert(remove_count == 7)
538+
assert(removed_sum == 42 + 42 + 43 + 44 + 45 + 46 + 47)
537539
end
538540

539541
do

evolved.lua

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,21 +2544,20 @@ function __chunk_remove(old_chunk, ...)
25442544
return
25452545
end
25462546

2547-
local old_fragment_set = old_chunk.__fragment_set
2547+
local old_fragment_list = old_chunk.__fragment_list
2548+
local old_fragment_count = old_chunk.__fragment_count
25482549
local old_component_indices = old_chunk.__component_indices
25492550
local old_component_storages = old_chunk.__component_storages
25502551

25512552
if old_chunk.__has_remove_hooks then
2552-
---@type table<evolved.fragment, boolean>
2553-
local removed_set = __acquire_table(__table_pool_tag.fragment_set)
2553+
---@type table<evolved.fragment, integer>
2554+
local new_fragment_set = new_chunk and new_chunk.__fragment_set
2555+
or __safe_tbls.__EMPTY_FRAGMENT_SET
25542556

2555-
for i = 1, fragment_count do
2556-
---@type evolved.fragment
2557-
local fragment = __lua_select(i, ...)
2558-
2559-
if not removed_set[fragment] and old_fragment_set[fragment] then
2560-
removed_set[fragment] = true
2557+
for i = 1, old_fragment_count do
2558+
local fragment = old_fragment_list[i]
25612559

2560+
if not new_fragment_set[fragment] then
25622561
---@type evolved.remove_hook?
25632562
local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE)
25642563

@@ -2582,8 +2581,6 @@ function __chunk_remove(old_chunk, ...)
25822581
end
25832582
end
25842583
end
2585-
2586-
__release_table(__table_pool_tag.fragment_set, removed_set)
25872584
end
25882585

25892586
if new_chunk then
@@ -3990,21 +3987,20 @@ function __evolved_remove(entity, ...)
39903987
__evolved_defer()
39913988

39923989
do
3993-
local old_fragment_set = old_chunk.__fragment_set
3990+
local old_fragment_list = old_chunk.__fragment_list
3991+
local old_fragment_count = old_chunk.__fragment_count
39943992
local old_component_indices = old_chunk.__component_indices
39953993
local old_component_storages = old_chunk.__component_storages
39963994

39973995
if old_chunk.__has_remove_hooks then
3998-
---@type table<evolved.fragment, boolean>
3999-
local removed_set = __acquire_table(__table_pool_tag.fragment_set)
3996+
---@type table<evolved.fragment, integer>
3997+
local new_fragment_set = new_chunk and new_chunk.__fragment_set
3998+
or __safe_tbls.__EMPTY_FRAGMENT_SET
40003999

4001-
for i = 1, fragment_count do
4002-
---@type evolved.fragment
4003-
local fragment = __lua_select(i, ...)
4004-
4005-
if not removed_set[fragment] and old_fragment_set[fragment] then
4006-
removed_set[fragment] = true
4000+
for i = 1, old_fragment_count do
4001+
local fragment = old_fragment_list[i]
40074002

4003+
if not new_fragment_set[fragment] then
40084004
---@type evolved.remove_hook?
40094005
local fragment_on_remove = __evolved_get(fragment, __ON_REMOVE)
40104006

@@ -4021,8 +4017,6 @@ function __evolved_remove(entity, ...)
40214017
end
40224018
end
40234019
end
4024-
4025-
__release_table(__table_pool_tag.fragment_set, removed_set)
40264020
end
40274021

40284022
if new_chunk then

0 commit comments

Comments
 (0)