From 641f444a0beec17ae93ca4af5a2992d1c31cef43 Mon Sep 17 00:00:00 2001 From: Gustavo Goretkin Date: Fri, 24 Apr 2020 18:27:32 +0200 Subject: [PATCH] Specialize `union` for `OneTo` (#35577) --- base/range.jl | 1 + test/ranges.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/base/range.jl b/base/range.jl index cabd16c61e3e8..60959420c2fe5 100644 --- a/base/range.jl +++ b/base/range.jl @@ -762,6 +762,7 @@ function ==(r::AbstractRange, s::AbstractRange) end intersect(r::OneTo, s::OneTo) = OneTo(min(r.stop,s.stop)) +union(r::OneTo, s::OneTo) = OneTo(max(r.stop,s.stop)) intersect(r::AbstractUnitRange{<:Integer}, s::AbstractUnitRange{<:Integer}) = max(first(r),first(s)):min(last(r),last(s)) diff --git a/test/ranges.jl b/test/ranges.jl index dd62524d37726..33a9ad43424d6 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -1232,6 +1232,7 @@ end @test i == (k += 1) end @test intersect(r, Base.OneTo(2)) == Base.OneTo(2) + @test union(r, Base.OneTo(4)) == Base.OneTo(4) @test intersect(r, 0:5) == 1:3 @test intersect(r, 2) === intersect(2, r) === 2:2 @test findall(in(r), r) === findall(in(1:length(r)), r) ===