diff options
author | Jille Timmermans <jille@quis.cx> | 2023-12-02 18:05:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-02 18:05:12 +0100 |
commit | 2ac2a3911bc0d9218d2ba2699c143a9a19540e76 (patch) | |
tree | a9cb67140fcba36c9b3ad4a84dbc86521801185d | |
parent | bug: Flush the write buffer before putting it to the pool (#1672) (diff) | |
download | fasthttp-2ac2a3911bc0d9218d2ba2699c143a9a19540e76.tar.gz fasthttp-2ac2a3911bc0d9218d2ba2699c143a9a19540e76.tar.bz2 fasthttp-2ac2a3911bc0d9218d2ba2699c143a9a19540e76.zip |
copyZeroAlloc: Try WriteTo and ReadFrom before acquiring a buffer (#1673)
These are the same statements at the beginning of io.CopyBuffer, but
by doing them ourselves first we trade off a little cpu for not holding
the 4kb buffer during the write.
-rw-r--r-- | http.go | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -2120,6 +2120,12 @@ func writeBodyFixedSize(w *bufio.Writer, r io.Reader, size int64) error { } func copyZeroAlloc(w io.Writer, r io.Reader) (int64, error) { + if wt, ok := r.(io.WriterTo); ok { + return wt.WriteTo(w) + } + if rt, ok := w.(io.ReaderFrom); ok { + return rt.ReadFrom(r) + } vbuf := copyBufPool.Get() buf := vbuf.([]byte) n, err := io.CopyBuffer(w, r, buf) |