Skip to content

Commit

Permalink
remove unnecessary ::Union{} type asserts (JuliaLang#35817)
Browse files Browse the repository at this point in the history
* remove unnecessary ::Union{} type asserts
  • Loading branch information
KristofferC committed Dec 29, 2020
1 parent ae3a3cc commit 345ce78
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ end
struct CodePointError{T<:Integer} <: Exception
code::T
end
@noinline invalid_char(c::AbstractChar) = throw(InvalidCharError(c))
@noinline code_point_err(u::Integer) = throw(CodePointError(u))
@noinline throw_invalid_char(c::AbstractChar) = throw(InvalidCharError(c))
@noinline throw_code_point_err(u::Integer) = throw(CodePointError(u))

function ismalformed(c::Char)
u = reinterpret(UInt32, c)
Expand Down Expand Up @@ -129,7 +129,7 @@ function UInt32(c::Char)
t0 = trailing_zeros(u) & 56
(l1 == 1) | (8l1 + t0 > 32) |
((((u & 0x00c0c0c0) 0x00808080) >> t0 != 0) | is_overlong_enc(u)) &&
invalid_char(c)::Union{}
throw_invalid_char(c)
u &= 0xffffffff >> l1
u >>= t0
((u & 0x0000007f) >> 0) | ((u & 0x00007f00) >> 2) |
Expand Down Expand Up @@ -157,7 +157,7 @@ end

function Char(u::UInt32)
u < 0x80 && return reinterpret(Char, u << 24)
u < 0x00200000 || code_point_err(u)::Union{}
u < 0x00200000 || throw_code_point_err(u)
c = ((u << 0) & 0x0000003f) | ((u << 2) & 0x00003f00) |
((u << 4) & 0x003f0000) | ((u << 6) & 0x3f000000)
c = u < 0x00000800 ? (c << 16) | 0xc0800000 :
Expand Down
10 changes: 5 additions & 5 deletions stdlib/LibGit2/src/LibGit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -963,11 +963,15 @@ end

const ENSURE_INITIALIZED_LOCK = ReentrantLock()

@noinline function throw_negative_refcount_error(x::Int)
error("Negative LibGit2 REFCOUNT $x\nThis shouldn't happen, please file a bug report!")
end

function ensure_initialized()
lock(ENSURE_INITIALIZED_LOCK) do
x = Threads.atomic_cas!(REFCOUNT, 0, 1)
x > 0 && return
x < 0 && negative_refcount_error(x)::Union{}
x < 0 && throw_negative_refcount_error(x)
try initialize()
catch
Threads.atomic_sub!(REFCOUNT, 1)
Expand All @@ -978,10 +982,6 @@ function ensure_initialized()
return nothing
end

@noinline function negative_refcount_error(x::Int)
error("Negative LibGit2 REFCOUNT $x\nThis shouldn't happen, please file a bug report!")
end

@noinline function initialize()
@check ccall((:git_libgit2_init, :libgit2), Cint, ())

Expand Down
2 changes: 1 addition & 1 deletion test/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@test widen('a') === 'a'
# just check this works
@test_throws Base.CodePointError Base.code_point_err(UInt32(1))
@test_throws Base.CodePointError Base.throw_code_point_err(UInt32(1))
end

@testset "ASCII conversion to/from Integer" begin
Expand Down

0 comments on commit 345ce78

Please sign in to comment.