Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,12 @@ function write(s::IO, a::SubArray{T,N,<:Array}) where {T,N}
end

function write(io::IO, c::Char)
u = bswap(reinterpret(UInt32, c))
n = 1
while true
write(io, u % UInt8)
(u >>= 8) == 0 && return n
n += 1
v = reinterpret(UInt32, c)
u = Ref{UInt32}(hton(v)) # BIG-endian
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an unconditional bswap since UTF-8 is independent of the endianess of the system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UTF-8 is independent of the endianess of the system.

Yes, it is true, but UInt32 isn't.

GC.@preserve u begin
p = unsafe_convert(Ptr{Cvoid}, u)
n = max(1, 4 - (trailing_zeros(v) >>> 3))
unsafe_write(io, p, n)
end
end
# write(io, ::AbstractChar) is not defined: implementations
Expand Down