Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wkb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Push WKB to `data` for a Pointlike `type` of `geom`.
function getwkb!(data::Vector{UInt8}, type::GI.PointTrait, geom, first::Bool)
ncoord = GI.ncoord(type, geom)
if first
sizehint!(data, 21)
isempty(data) && sizehint!(data, 21)
push!(data, 0x01) # endianness
wkbtype = geometry_code(type)
ncoord == 3 && (wkbtype |= wkbZ)
Expand Down Expand Up @@ -110,7 +110,7 @@ a geometrycollection.
"""
function _getwkb!(data::Vector{UInt8}, type, geom, first::Bool, repeat::Bool)
if first
sizehint!(data, 42) # smallest non-point geometry is a line with 2 points
isempty(data) && sizehint!(data, 42) # smallest non-point geometry is a line with 2 points
push!(data, 0x01) # endianness
wkbtype = geometry_code(type)
ncoord = GI.ncoord(type, geom)
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,18 @@ import LibGEOS
wkbc = WKG.wkb"01010000000000000000003e400000000000002440"
@test wkba == wkbb == wkbc
end

@testset "Allocation" begin
ring(n) = GI.LinearRing([(Float64(i), Float64(i)) for i in 1:n])
mpoly(k) = GI.MultiPolygon([GI.Polygon([ring(100_000 ÷ k)]) for _ in 1:k]) # 100k vertices total

mp = mpoly(1)
WKG.getwkb(mp) # warmup
a = @allocated WKG.getwkb(mp)
for k in (1, 25, 50, 100)
mp = mpoly(k)
b = @allocated WKG.getwkb(mp)
@test a == b
end
end
end
Loading