diff --git a/packages/ludic.base/ecs_index_slot.ludic b/packages/ludic.base/ecs_index_slot.ludic index e35155c9..c4c2a4a5 100644 --- a/packages/ludic.base/ecs_index_slot.ludic +++ b/packages/ludic.base/ecs_index_slot.ludic @@ -2,6 +2,13 @@ # slot; a large one (a chunk's packed cell) is given the next slot through a map, so a sparse # value costs one list and not every list up to it const IX_DENSE: int = 1024 # a value below this is its own slot; above, one is given it +const IX_CAP: int = 16 # rows a value's list holds before it grows: a list grown in play is a new block + +function ix_list_new() -> words { + let l = words(IX_CAP) + List.clear(l) + return l +} # the slot value v's list is in, -1 when it has none (and `make` did not ask for one) function ix_slot(ix: IntIndex, v: int, make: bool) -> int { @@ -9,15 +16,15 @@ function ix_slot(ix: IntIndex, v: int, make: bool) -> int { if v < IX_DENSE { if v >= len(ix.lists) { if not make { return -1 } - while len(ix.lists) <= v { push(ix.lists, words(0)) } + while len(ix.lists) <= v { push(ix.lists, ix_list_new()) } } return v } var s = imap_get(ix.sparse, v, -1) if s < 0 and make { - while len(ix.lists) < IX_DENSE { push(ix.lists, words(0)) } + while len(ix.lists) < IX_DENSE { push(ix.lists, ix_list_new()) } s = len(ix.lists) - push(ix.lists, words(0)) + push(ix.lists, ix_list_new()) imap_put(ix.sparse, v, s) } return s