Skip to content

Commit 3315760

Browse files
authored
fix SVector inferrability (#329)
1 parent 5fdce7e commit 3315760

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/common.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,10 @@ end
415415

416416
is_auto(lims) = all(iszero, lims)
417417

418-
autolims(lims) = is_auto(lims) ? SVector(-1.0, 1.0) : SVector(as_float(lims))
418+
# NOTE: we need `SVector{2}(v)` for compiler inferrability, not `Svector(v)` !
419+
autolims(lims) = is_auto(lims) ? SVector(-1.0, 1.0) : SVector{2}(as_float(lims))
419420
autolims(lims, vec::AbstractVector) =
420-
is_auto(lims) && length(vec) > 0 ? SVector(extrema(vec)) : SVector(as_float(lims))
421+
is_auto(lims) && length(vec) > 0 ? SVector{2}(extrema(vec)) : SVector{2}(as_float(lims))
421422

422423
scale_callback(scale::Symbol) = FSCALES[scale]
423424
scale_callback(scale::Function) = scale

src/interface/heatmap.jl

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ function heatmap(
8686
end .+ xoffset
8787

8888
# set the axis limits automatically
89-
9089
ylim = autolims(ylim, Y)
9190
xlim = autolims(xlim, X)
9291

src/volume.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ struct MVP{E,T}
272272
end
273273
end
274274

275-
create_MVP(::Nothing, args...; kw...) = (warn_on_lost_kw(kw); MVP())
276275
create_MVP(projection::Symbol, args...; kw...) = MVP(args...; projection, kw...)
277-
create_MVP(projection::MVP, args...; kw...) = (warn_on_lost_kw(kw); projection)
276+
create_MVP(projection::MVP, args...; _...) = projection # NOTE: kw are expected to be lost (see Plots)
277+
create_MVP(::Nothing, args...; _...) = MVP() # NOTE: kw are expected to be lost (see Plots)
278278

279279
@inline is_enabled(::MVP{Val{false}}) = false
280280
@inline is_enabled(::MVP{Val{true}}) = true

test/tst_common.jl

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ end
4040
@test UnicodePlots.is_auto([0, 0])
4141
@test !UnicodePlots.is_auto((-1, 1))
4242
@test !UnicodePlots.is_auto([-1, 1])
43+
44+
# `SVector` inferrability
45+
@test UnicodePlots.autolims([-3, 2]) == [-3, 2]
46+
@test UnicodePlots.autolims([-3, 2], 1:10) == [-3, 2]
47+
@test UnicodePlots.autolims([0, 0], 1:10) == [1, 10]
4348
end
4449

4550
@testset "bordermap" begin

0 commit comments

Comments
 (0)