Skip to content

Commit bbb0596

Browse files
Perf improvement for 2 arg show for UnitRange type (#57823)
Mentioned in #57697 (comment) and #57697 (comment) also improves #57697 benchmarks on my configuration: ```julia julia> f(io, a) = print(io, repr(first(a)), ':', repr(last(a))) f (generic function with 1 method) julia> function g(io, a) show(io, first(a)) print(io, ':') show(io, last(a)) end g (generic function with 1 method) julia> using BenchmarkTools julia> @Btime f(io, a) setup=(io=devnull; a=big(2)^(2^10):big(6)^(2^10);) 4.889 μs (17 allocations: 5.23 KiB) julia> @Btime g(io, a) setup=(io=devnull; a=big(2)^(2^10):big(6)^(2^10);) 4.021 μs (11 allocations: 3.86 KiB) julia> @Btime f(io, a) setup=(io=devnull; a=10000000000000000:10000000000000001;) 312.814 ns (12 allocations: 576 bytes) julia> @Btime g(io, a) setup=(io=devnull; a=10000000000000000:10000000000000001;) 62.859 ns (4 allocations: 208 bytes) ```
1 parent c7a28b2 commit bbb0596

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

base/range.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,11 @@ function getindex(r::LinRange{T}, s::OrdinalRange{S}) where {T, S<:Integer}
11051105
end
11061106

11071107
show(io::IO, r::AbstractRange) = print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r)))
1108-
show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r)))
1108+
function show(io::IO, r::UnitRange)
1109+
show(io, first(r))
1110+
print(io, ':')
1111+
show(io, last(r))
1112+
end
11091113
show(io::IO, r::OneTo) = print(io, "Base.OneTo(", r.stop, ")")
11101114
function show(io::IO, r::StepRangeLen)
11111115
if !iszero(step(r))

0 commit comments

Comments
 (0)