fix(base): a queue drain allocates nothing - two lists, reused

The rest of the leak Physics found: a drain that carried facts gave its list away and made a new
one, every queue every frame something happened. The queue keeps two lists and hands one out while
the other fills; a drained list is good until the next drain of that queue (nothing in the game or
the packages keeps one past it). With ab34f82's empty drain and in-place clear, a queue allocates
nothing in steady state. queue_test holds the reuse; every package (403) and lab/unit (90) pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 22:55:43 +03:00
parent 8384ad3215
commit c74099f5f8
2 changed files with 26 additions and 4 deletions

View file

@ -87,6 +87,23 @@ program QueueTest {
}
test "a queue drains in the order it was pushed" () { fifo_case() }
# two lists, reused: a drained list is the caller's until the next drain of that queue
function reuse_case() -> void {
let q: Queue<int> = queue_new("reused")
q_push(q, 1)
let a = q_drain(q)
q_push(q, 2)
expect_eq(a[0], 1)
let b = q_drain(q)
expect_eq(b[0], 2)
q_push(q, 3)
let c = q_drain(q)
expect(c == a)
expect_eq(len(c), 1)
expect_eq(c[0], 3)
}
test "a drain reuses the queue's two lists" () { reuse_case() }
test "an empty drain allocates nothing, and a drained list is the caller's" () { empty_case() }
test "a queue holds records" () { record_case() }
test "clear drops what is waiting" () { clear_case() }