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.
This commit is contained in:
Tetralux
2020-10-26 00:12:31 +00:00
committed by GitHub
parent 4629754f7c
commit 213864a50c
+3
View File
@@ -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;
}