Skip to content

Commit

Permalink
Use Base._unsetindex! in pop! and popfirst! for Deque
Browse files Browse the repository at this point in the history
So that popped elements are not rooted by the deque and can be
GCed when they drop out of caller scope.
  • Loading branch information
kpamnany committed Feb 16, 2024
1 parent 1b1d67b commit a102588
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ function Base.pop!(d::Deque{T}) where T
@assert rear.back >= rear.front

@inbounds x = rear.data[rear.back]
Base._unsetindex!(rear.data, rear.back)
rear.back -= 1
if rear.back < rear.front
if d.nblocks > 1
Expand All @@ -322,6 +323,7 @@ function Base.popfirst!(d::Deque{T}) where T
@assert head.back >= head.front

@inbounds x = head.data[head.front]
Base._unsetindex!(head.data, head.front)
head.front += 1
if head.back < head.front
if d.nblocks > 1
Expand Down

0 comments on commit a102588

Please sign in to comment.