From 6ba78767d79bee06686bc40c6239f6231ec28c16 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 6 Sep 2018 14:03:05 -0400 Subject: [PATCH] work around a splatting penalty in twiceprecision (#29060) * work around a splatting penalty in twiceprecision * add allocation test (cherry picked from commit 88d536a1ea8903dfdfd78f86a5be75eedcfddf5a) --- base/twiceprecision.jl | 7 +++++-- test/ranges.jl | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index cf61823ecc0f6..e80c87c2eb8e5 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -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, diff --git a/test/ranges.jl b/test/ranges.jl index 5817871b04050..ad720f7a2553f 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -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