Skip to content

Commit

Permalink
fix bug in pop! and popfirst! (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl-solution authored Apr 19, 2022
1 parent 978b55d commit d84c4be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PooledArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,14 @@ function Base.append!(pv::PooledVector, items::AbstractArray)
return pv
end

Base.pop!(pv::PooledVector) = pv.invpool[pop!(pv.refs)]
Base.pop!(pv::PooledVector) = pv.pool[pop!(pv.refs)]

function Base.pushfirst!(pv::PooledVector{S,R}, v::T) where {S,R,T}
pushfirst!(pv.refs, getpoolidx(pv, v))
return pv
end

Base.popfirst!(pv::PooledVector) = pv.invpool[popfirst!(pv.refs)]
Base.popfirst!(pv::PooledVector) = pv.pool[popfirst!(pv.refs)]

Base.empty!(pv::PooledVector) = (empty!(pv.refs); pv)

Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,16 @@ end
@test_throws BoundsError insert!(x, 9, true)
@test x == [1, 1, 10, 99, 2, 3, 1]
end

@testset "pop! and popfirst!" begin
x = PooledArray([1, 2, 3])
@test pop!(x) == 3
@test x == [1, 2]
@test popfirst!(x) == 1
@test x == [2]
x = PooledArray(["1", "2", "3"])
@test pop!(x) == "3"
@test x == ["1", "2"]
@test popfirst!(x) == "1"
@test x == ["2"]
end

0 comments on commit d84c4be

Please sign in to comment.