Skip to content

Commit

Permalink
Fix some performance issues due to new InexactError
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jul 10, 2017
1 parent 43175dd commit 829216a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const BitIntegerSmall = Union{BitIntegerSmall_types...}
const BitSigned64T = Union{Type{Int8}, Type{Int16}, Type{Int32}, Type{Int64}}
const BitUnsigned64T = Union{Type{UInt8}, Type{UInt16}, Type{UInt32}, Type{UInt64}}

throw_inexacterror(f::Symbol, ::Type{T}, val) where T =
(@_noinline_meta; throw(InexactError(f, T, val)))

## integer comparisons ##

(<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y)
Expand Down Expand Up @@ -401,7 +404,7 @@ function is_top_bit_set(x::BitInteger)
end
function check_top_bit(x::BitInteger)
@_inline_meta
is_top_bit_set(x) && throw(InexactError(:check_top_bit, Integer, x))
is_top_bit_set(x) && throw_inexacterror(:check_top_bit, typeof(x), x)
x
end

Expand All @@ -411,15 +414,15 @@ function checked_trunc_sint{To,From}(::Type{To}, x::From)
@_inline_meta
y = trunc_int(To, x)
back = sext_int(From, y)
x == back || throw(InexactError(:trunc, To, x))
x == back || throw_inexacterror(:trunc, To, x)
y
end

function checked_trunc_uint{To,From}(::Type{To}, x::From)
@_inline_meta
y = trunc_int(To, x)
back = zext_int(From, y)
x == back || throw(InexactError(:trunc, To, x))
x == back || throw_inexacterror(:trunc, To, x)
y
end

Expand Down

0 comments on commit 829216a

Please sign in to comment.