Skip to content

Commit a2bc2e0

Browse files
authored
Specialize functions to avoid dynamic dispatch (#985)
* Specialize functions to avoid dynamic dispatch This helps reduce allocations and make client requests a little more stable with regards to allocations and performance. * Fix specializations
1 parent 47c24c9 commit a2bc2e0

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/ConnectionPool.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ end
211211
Read until `find_delimiter(bytes)` returns non-zero.
212212
Return view of bytes up to the delimiter.
213213
"""
214-
function Base.readuntil(c::Connection, f::Function #=Vector{UInt8} -> Int=#,
215-
sizehint=4096)::ByteView
214+
function Base.readuntil(c::Connection, f::F #=Vector{UInt8} -> Int=#,
215+
sizehint=4096)::ByteView where {F <: Function}
216216
buf = c.buffer
217217
if bytesavailable(buf) == 0
218218
read_to_buffer(c, sizehint)

src/IOExtras.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ Read from an `IO` stream until `find_delimiter(bytes)` returns non-zero.
112112
Return view of bytes up to the delimiter.
113113
"""
114114
function Base.readuntil(buf::IOBuffer,
115-
find_delimiter::Function #= Vector{UInt8} -> Int =#
116-
)::ByteView
117-
115+
find_delimiter::F #= Vector{UInt8} -> Int =#
116+
)::ByteView where {F <: Function}
118117
l = find_delimiter(view(buf.data, buf.ptr:buf.size))
119118
if l == 0
120119
return nobytes

0 commit comments

Comments
 (0)