aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jille Timmermans <jille@quis.cx> 2023-12-02 18:05:12 +0100
committerGravatar GitHub <noreply@github.com> 2023-12-02 18:05:12 +0100
commit2ac2a3911bc0d9218d2ba2699c143a9a19540e76 (patch)
treea9cb67140fcba36c9b3ad4a84dbc86521801185d
parentbug: Flush the write buffer before putting it to the pool (#1672) (diff)
downloadfasthttp-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.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/http.go b/http.go
index d134b62..4f8718c 100644
--- a/http.go
+++ b/http.go
@@ -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)