From 8ee21d4d6d9ad96e86f9d682ac602f831108e954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Drvo=C5=A1t=C4=9Bp?= Date: Fri, 17 May 2024 22:35:06 +0200 Subject: [PATCH] Fix accidental piracy in `BufferedVector` --- src/BufferedVectors.jl | 2 +- test/BufferedVectors.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/BufferedVectors.jl b/src/BufferedVectors.jl index b7cca56..9c4cf7e 100644 --- a/src/BufferedVectors.jl +++ b/src/BufferedVectors.jl @@ -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)) diff --git a/test/BufferedVectors.jl b/test/BufferedVectors.jl index 7a0c41b..596d226 100644 --- a/test/BufferedVectors.jl +++ b/test/BufferedVectors.jl @@ -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)