Skip to content

Commit 0ac1528

Browse files
authored
Use Base.alloc_request instead of implementing it directly (#1145)
There is slightly better error handling in this function, which avoids relying as directly on implementation details of IOBuffer.
1 parent 22ce15a commit 0ac1528

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/Connections.jl

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ end
213213
function read_to_buffer(c::Connection, sizehint=4096)
214214
buf = c.buffer
215215

216-
# Reset the buffer if it is empty.
217-
if bytesavailable(buf) == 0
218-
buf.size = 0
219-
buf.ptr = 1
220-
end
221-
222216
# Wait for data.
223217
if eof(c.io)
224218
throw(EOFError())
@@ -227,9 +221,11 @@ function read_to_buffer(c::Connection, sizehint=4096)
227221
# Read from stream into buffer.
228222
n = min(sizehint, bytesavailable(c.io))
229223
buf = c.buffer
230-
Base.ensureroom(buf, n)
231-
GC.@preserve buf unsafe_read(c.io, pointer(buf.data, buf.size + 1), n)
232-
buf.size += n
224+
p, n = Base.alloc_request(buf, UInt(n))
225+
n = min(n, bytesavailable(c.io))
226+
GC.@preserve buf unsafe_read(c.io, p, UInt(n))
227+
Base.notify_filled(buf, Int(n))
228+
nothing
233229
end
234230

235231
"""

0 commit comments

Comments
 (0)