mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-22 21:54:59 -07:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user