Skip to content

Commit

Permalink
Use Base._unsetindex! in pop! and popfirst! for CircularDeque
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 20, 2024
1 parent 04ad0a7 commit acc6ad8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/circ_deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ end

@inline Base.@propagate_inbounds function Base.pop!(D::CircularDeque)
v = last(D)
Base._unsetindex!(D.buffer, D.last)
D.n -= 1
tmp = D.last - 1
D.last = ifelse(tmp < 1, D.capacity, tmp)
Expand Down Expand Up @@ -91,6 +92,7 @@ Remove the element at the front.
"""
@inline Base.@propagate_inbounds function Base.popfirst!(D::CircularDeque)
v = first(D)
Base._unsetindex!(D.buffer, D.first)
D.n -= 1
tmp = D.first + 1
D.first = ifelse(tmp > D.capacity, 1, tmp)
Expand Down

0 comments on commit acc6ad8

Please sign in to comment.