Skip to content

Commit 2af5c86

Browse files
authored
inline arithmetic between chars and Integers (#32681)
1 parent c0478d8 commit 2af5c86

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

base/char.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ isless(x::AbstractChar, y::AbstractChar) = isless(Char(x), Char(y))
218218
hash(x::AbstractChar, h::UInt) = hash(Char(x), h)
219219
widen(::Type{T}) where {T<:AbstractChar} = T
220220

221-
-(x::AbstractChar, y::AbstractChar) = Int(x) - Int(y)
222-
-(x::T, y::Integer) where {T<:AbstractChar} = T(Int32(x) - Int32(y))
223-
+(x::T, y::Integer) where {T<:AbstractChar} = T(Int32(x) + Int32(y))
224-
+(x::Integer, y::AbstractChar) = y + x
221+
@inline -(x::AbstractChar, y::AbstractChar) = Int(x) - Int(y)
222+
@inline -(x::T, y::Integer) where {T<:AbstractChar} = T(Int32(x) - Int32(y))
223+
@inline +(x::T, y::Integer) where {T<:AbstractChar} = T(Int32(x) + Int32(y))
224+
@inline +(x::Integer, y::AbstractChar) = y + x
225225

226226
# `print` should output UTF-8 by default for all AbstractChar types.
227227
# (Packages may implement other IO subtypes to specify different encodings.)

0 commit comments

Comments
 (0)