Skip to content

Commit

Permalink
work around a splatting penalty in twiceprecision (JuliaLang#29060)
Browse files Browse the repository at this point in the history
* work around a splatting penalty in twiceprecision

* add allocation test
  • Loading branch information
KristofferC authored Sep 6, 2018
1 parent e5cc750 commit 88d536a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions base/twiceprecision.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,14 @@ const F_or_FF = Union{AbstractFloat, Tuple{AbstractFloat,AbstractFloat}}
asF64(x::AbstractFloat) = Float64(x)
asF64(x::Tuple{AbstractFloat,AbstractFloat}) = Float64(x[1]) + Float64(x[2])

# Defined to prevent splatting in the function below which here has a performance impact
_TP(x) = TwicePrecision{Float64}(x)
_TP(x::Tuple{Any, Any}) = TwicePrecision{Float64}(x[1], x[2])
function steprangelen_hp(::Type{Float64}, ref::F_or_FF,
step::F_or_FF, nb::Integer,
len::Integer, offset::Integer)
StepRangeLen(TwicePrecision{Float64}(ref...),
twiceprecision(TwicePrecision{Float64}(step...), nb), Int(len), offset)
StepRangeLen(_TP(ref),
twiceprecision(_TP(step), nb), Int(len), offset)
end

function steprangelen_hp(::Type{T}, ref::F_or_FF,
Expand Down
7 changes: 7 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,10 @@ end # module NonStandardIntegerRangeTest
end
end
end

@testset "allocation of TwicePrecision call" begin
0:286.493442:360
0:286:360
@test @allocated(0:286.493442:360) == 0
@test @allocated(0:286:360) == 0
end

0 comments on commit 88d536a

Please sign in to comment.