From 41fee11f66d5ecc498de18216cb308fba5ef0114 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Thu, 5 Mar 2020 21:06:16 +0100 Subject: [PATCH] Micro-optimization for hashing.Writer/PackerManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta PackerManager-8 247ms ± 1% 246ms ± 1% -0.43% (p=0.001 n=18+18) name old speed new speed delta PackerManager-8 213MB/s ± 1% 214MB/s ± 1% +0.43% (p=0.001 n=18+18) name old alloc/op new alloc/op delta PackerManager-8 92.2kB ± 0% 91.5kB ± 0% -0.82% (p=0.000 n=19+20) name old allocs/op new allocs/op delta PackerManager-8 1.43k ± 0% 1.41k ± 0% -1.67% (p=0.000 n=20+20) --- internal/hashing/writer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/hashing/writer.go b/internal/hashing/writer.go index 2940a6271..8eb157a9f 100644 --- a/internal/hashing/writer.go +++ b/internal/hashing/writer.go @@ -15,13 +15,14 @@ type Writer struct { func NewWriter(w io.Writer, h hash.Hash) *Writer { return &Writer{ h: h, - w: io.MultiWriter(w, h), + w: w, } } // Write wraps the write method of the underlying writer and also hashes all data. func (h *Writer) Write(p []byte) (int, error) { n, err := h.w.Write(p) + h.h.Write(p[:n]) return n, err }