Fix #4422: Reset queue element on pop. Prevent NimVM confusion. Help GC.
This commit is contained in:
parent
d7e172a6bc
commit
90a5edfa6d
1 changed files with 2 additions and 0 deletions
|
|
@ -152,11 +152,13 @@ proc add*[T](q: var Queue[T], item: T) =
|
||||||
q.data[q.wr] = item
|
q.data[q.wr] = item
|
||||||
q.wr = (q.wr + 1) and q.mask
|
q.wr = (q.wr + 1) and q.mask
|
||||||
|
|
||||||
|
proc default[T](t: typedesc[T]): T {.inline.} = discard
|
||||||
proc pop*[T](q: var Queue[T]): T {.inline, discardable.} =
|
proc pop*[T](q: var Queue[T]): T {.inline, discardable.} =
|
||||||
## Remove and returns the first (oldest) element of the queue `q`.
|
## Remove and returns the first (oldest) element of the queue `q`.
|
||||||
emptyCheck(q)
|
emptyCheck(q)
|
||||||
dec q.count
|
dec q.count
|
||||||
result = q.data[q.rd]
|
result = q.data[q.rd]
|
||||||
|
q.data[q.rd] = default(type(result))
|
||||||
q.rd = (q.rd + 1) and q.mask
|
q.rd = (q.rd + 1) and q.mask
|
||||||
|
|
||||||
proc enqueue*[T](q: var Queue[T], item: T) =
|
proc enqueue*[T](q: var Queue[T], item: T) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue