From 213864a50c653903f41f9e2f4a5e84b9a82b9ea0 Mon Sep 17 00:00:00 2001 From: Tetralux Date: Mon, 26 Oct 2020 00:12:31 +0000 Subject: [PATCH] Reuse container.Queue capacity when calling pop_front() Currently, the Queue will never reuse it's full capacity if you call `pop_front`, even if you empty it before pushing more items. With this change, if you empty the Queue with `pop_front`, then the offset will be set back to the start of the underlying array when you pop the last item. Future pushes will then reuse the already-allocated--but now empty--space. --- core/container/queue.odin | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/container/queue.odin b/core/container/queue.odin index 6e7e79ad3..2664b9a08 100644 --- a/core/container/queue.odin +++ b/core/container/queue.odin @@ -115,6 +115,9 @@ queue_pop_front :: proc(q: ^$Q/Queue($T)) -> T { item := queue_get(q^, 0); q.offset = (q.offset + 1) % array_len(q.data); q.len -= 1; + if q.len == 0 { + q.offset = 0; + } return item; }