Skip to content

Commit

Permalink
Fix accidental piracy in BufferedVector
Browse files Browse the repository at this point in the history
  • Loading branch information
Drvi committed May 17, 2024
1 parent f9e11b7 commit 8ee21d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BufferedVectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Base.IteratorSize(::BufferedVector) = Base.HasLength()
Base.IteratorEltype(::BufferedVector) = Base.HasEltype()
Base.collect(x::BufferedVector{T}) where {T} = length(x) > 0 ? @inbounds(x.elements[1:length(x)]) : T[]
Base.eltype(::BufferedVector{T}) where T = T
@inline Base.push!(buffer::T, x::S) where {T,S} = push!(buffer, convert(T, x))
@inline Base.push!(buffer::BufferedVector{T}, x::S) where {T,S} = push!(buffer, convert(T, x))
@inline function Base.push!(buffer::BufferedVector{T}, x::T) where {T}
if length(buffer.elements) == buffer.occupied
Base._growend!(buffer.elements, _grow_by(T))
Expand Down
5 changes: 5 additions & 0 deletions test/BufferedVectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ using SentinelArrays: BufferedVectors
skip_element!(bv)
@test length(bv) == 2

empty!(bv)
push!(bv, 2.0) # convert
@test bv == [2]
@assert length(bv) == 1

bv = BufferedVector{Int}()
push!(bv, 1)
@test length(bv.elements) == BufferedVectors._grow_by(Int)
Expand Down

0 comments on commit 8ee21d4

Please sign in to comment.