Browse Source

container/queue: Let queues be re-initialized with different allocators

Feoramund 3 months ago
parent
commit
040d79e1b9
1 changed files with 6 additions and 3 deletions
  1. 6 3
      core/container/queue/queue.odin

+ 6 - 3
core/container/queue/queue.odin

@@ -23,10 +23,13 @@ DEFAULT_CAPACITY :: 16
 Initialize a `Queue` with a starting `capacity` and an `allocator`.
 Initialize a `Queue` with a starting `capacity` and an `allocator`.
 */
 */
 init :: proc(q: ^$Q/Queue($T), capacity := DEFAULT_CAPACITY, allocator := context.allocator) -> runtime.Allocator_Error {
 init :: proc(q: ^$Q/Queue($T), capacity := DEFAULT_CAPACITY, allocator := context.allocator) -> runtime.Allocator_Error {
-	if q.data.allocator.procedure == nil {
-		q.data.allocator = allocator
-	}
 	clear(q)
 	clear(q)
+	q.data = transmute([dynamic]T)runtime.Raw_Dynamic_Array{
+		data = nil,
+		len = 0,
+		cap = 0,
+		allocator = allocator,
+	}
 	return reserve(q, capacity)
 	return reserve(q, capacity)
 }
 }