Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add optimized IO methods #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alyst wants to merge 1 commit into JuliaStrings:master
base: master
Choose a base branch
Loading
from alyst:optimized_io
Open
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
22 changes: 22 additions & 0 deletions src/StringEncodings.jl
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ function write(s::StringEncoder, x::UInt8)
1
end

# Optimized IO implementation
function Base.unsafe_write(s::StringEncoder, p::Ptr{UInt8}, n::UInt)
bytes = unsafe_wrap(Array, p, n)
written = 0
while n > 0
if s.inbytesleft[] >= length(s.inbuf)
flush(s)
end
chunksize = min(n, length(s.inbuf) - s.inbytesleft[])
copyto!(s.inbuf, s.inbytesleft[]+1, bytes, written+1, chunksize)
s.inbytesleft[] += chunksize
written += chunksize
n -= chunksize
end
return written
end

## StringDecoder

Expand Down Expand Up @@ -428,6 +444,12 @@ function readbytes!(s::StringDecoder, b::AbstractArray{UInt8}, nb=length(b))
return nr
end

# Optimized IO implementation
function Base.unsafe_read(s::StringDecoder, p::Ptr{UInt8}, n::UInt)
readbytes!(s, unsafe_wrap(Array, p, n))
nothing
end

"""
read(stream::IO, [nb::Integer,] enc::Encoding)
read(filename::AbstractString, [nb::Integer,] enc::Encoding)
Expand Down

AltStyle によって変換されたページ (->オリジナル) /