fix(base): an empty queue drains and clears without allocating
Ludic frees nothing a safe program allocates, and every package's fact queue is drained once a frame: q_drain handed back its list and made a new one each time, most often of an empty queue. An empty drain now returns the queue's one shared empty list (never to be pushed to), and q_clear clears in place - the live list is never one a drain handed out. A queue that held facts still gives its list away, so what leaks is in proportion to what happened, not to the frame rate. queue_test holds it (an empty drain is the same list twice; a drained list is untouched by later pushes and clears). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f802bdd3ec
commit
ab34f8229b
2 changed files with 28 additions and 2 deletions
|
|
@ -67,7 +67,27 @@ program QueueTest {
|
|||
expect_eq(len(core_undrained(tags)), 0)
|
||||
}
|
||||
|
||||
# an empty drain allocates nothing and hands back the same empty list; a drained list is the
|
||||
# caller's, untouched by what is pushed or cleared after it
|
||||
function empty_case() -> void {
|
||||
let q: Queue<int> = queue_new("quiet")
|
||||
let a = q_drain(q)
|
||||
let b = q_drain(q)
|
||||
expect_eq(len(a), 0)
|
||||
expect(a == b)
|
||||
q_push(q, 5)
|
||||
expect_eq(len(a), 0)
|
||||
let got = q_drain(q)
|
||||
q_push(q, 6)
|
||||
q_clear(q)
|
||||
expect_eq(len(got), 1)
|
||||
expect_eq(got[0], 5)
|
||||
expect_eq(q_len(q), 0)
|
||||
expect_eq(len(q_drain(q)), 0)
|
||||
}
|
||||
|
||||
test "a queue drains in the order it was pushed" () { fifo_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() }
|
||||
test "a queue's element type is told by the queue alone" () { infer_case() }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue