Skip to content

Commit 94c8e69

Browse files
Char: remove many (unnecessary) Char arithmetic operations.
Spurred by #1771. The one I really wanted to get rid of was Char+Char but that's used by iteration of Char ranges, e.g. here: https://github.com/JuliaLang/julia/blob/63dd47153097c68643dd3462656a6c74358d04e3/base/intfuncs.jl#L220 In order to get rid of that usage, the way Range iteration works would need to be changed. Currently it's a bit odd that 'a':'z' is a Range of Chars, while 'a':1:'z' is a Range of Ints. Maybe the step type of a Range shouldn't need to be the same as the start type?
1 parent 0276c05 commit 94c8e69

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

base/char.jl

+4-14
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,10 @@ promote_rule(::Type{Char}, ::Type{Uint128}) = Uint128
4242

4343
## character operations & comparisons ##
4444

45-
-(x::Char) = -int(x)
46-
+(x::Char, y::Char) = int(x) + int(y)
47-
-(x::Char, y::Char) = int(x) - int(y)
48-
*(x::Char, y::Char) = int(x) * int(y)
49-
50-
div(x::Char, y::Char) = div(int(x), int(y))
51-
fld(x::Char, y::Char) = div(int(x), int(y))
52-
rem(x::Char, y::Char) = rem(int(x), int(y))
53-
mod(x::Char, y::Char) = rem(int(x), int(y))
54-
55-
~(x::Char) = ~uint32(x)
56-
(&)(x::Char, y::Char) = uint32(x) & uint32(y)
57-
|(x::Char, y::Char) = uint32(x) | uint32(y)
58-
($)(x::Char, y::Char) = uint32(x) $ uint32(y)
45+
-(x::Char, y::Char) = int(x)-int(y)
46+
+(x::Char, y::Char) = char(int(x)+int(y)) # TODO: delete me
47+
+(x::Char, y::Int ) = char(int(x)+y)
48+
+(x::Int , y::Char) = y+x
5949

6050
<<(x::Char, y::Int32) = uint32(x) << y
6151
>>(x::Char, y::Int32) = uint32(x) >>> y

0 commit comments

Comments
 (0)