Repository: JuliaLang/julia
File: base/show.jl (Julia)

Code before:
# This file is a part of Julia. License is MIT: https://julialang.org/license

using .Compiler: has_typevar

function show(io::IO, ::MIME"text/plain", u::UndefInitializer)
    show(io, u)
    get(io, :compact, false)::Bool && return
    print(io, ": array initializer with undefined values")
end

# first a few multiline show functions for types defined before the MIME type:

show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges

function show(io::IO, ::MIME"text/plain", r::UnitRange)
    print(io, repr(first(r)), ':', repr(last(r)))
    if !get(io, :compact, false) && isempty(r)
        print(io, " (empty range)")
    end
end

function show(io::IO, ::MIME"text/plain", r::LinRange)
    isempty(r) && return show(io, r)
    # show for LinRange, e.g.
    # range(1, stop=3, length=7)
    # 7-element LinRange{Float64}:
    #   1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0
    summary(io, r)
    println(io, ":")
    print_range(io, r)
end

function show(io::IO, ::MIME"text/plain", r::LogRange)  # display LogRange like LinRange
    isempty(r) && return show(io, r)
    summary(io, r)
    println(io, ":")
    print_range(io, r, " ", ", ", "", " \u2026 ")
end

function _isself(ft::DataType)
    ftname = ft.name

Review comment (performance):
More efficient:

```suggestion
    show(io, first(r))
    print(io, ':')
    show(io, last(r))
```

Proof:

```julia-repl
julia> f(io, a, b) = print(io, repr(a), ':', repr(b))
f (generic function with 1 method)

julia> function g(io, a, b)
           show(io, a)
           print(io, ':')
           show(io, b)
       end
g (generic function with 1 method)

julia> using BenchmarkTools

julia> @btime f(io, a, b) setup=(io = devnull; a = big(2)^(2^10); b = a + 1;)
  2.547 μs (12 allocations: 1.62 KiB)

julia> @btime g(io, a, b) setup=(io = devnull; a = big(2)^(2^10); b = a + 1;)
  2.201 μs (4 allocations: 736 bytes)
```

Code after:
# This file is a part of Julia. License is MIT: https://julialang.org/license

using .Compiler: has_typevar

function show(io::IO, ::MIME"text/plain", u::UndefInitializer)
    show(io, u)
    get(io, :compact, false)::Bool && return
    print(io, ": array initializer with undefined values")
end

# first a few multiline show functions for types defined before the MIME type:

show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges

function show(io::IO, ::MIME"text/plain", r::UnitRange)
    show(io, r)
    if !(get(io, :compact, false)::Bool) && isempty(r)
        print(io, " (empty range)")
    end
end

function show(io::IO, ::MIME"text/plain", r::LinRange)
    isempty(r) && return show(io, r)
    # show for LinRange, e.g.
    # range(1, stop=3, length=7)
    # 7-element LinRange{Float64}:
    #   1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0
    summary(io, r)
    println(io, ":")
    print_range(io, r)
end

function show(io::IO, ::MIME"text/plain", r::LogRange)  # display LogRange like LinRange
    isempty(r) && return show(io, r)
    summary(io, r)
    println(io, ":")
    print_range(io, r, " ", ", ", "", " \u2026 ")
end

function _isself(ft::DataType)
    ftname = ft.name