From d4c4b1fb4cdf9e4c2491027bc8a8ca20125ca8c2 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 18 Jan 2017 18:45:29 +0100 Subject: [PATCH] vendor: Temporarily patch github.com/chmduquesne/rollinghash To avoid allocations in the hasher. PR files, should be available for update soon. --- .../chmduquesne/rollinghash/adler32/adler32.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vendor/github.com/chmduquesne/rollinghash/adler32/adler32.go b/vendor/github.com/chmduquesne/rollinghash/adler32/adler32.go index 643a5987..b8630b2e 100644 --- a/vendor/github.com/chmduquesne/rollinghash/adler32/adler32.go +++ b/vendor/github.com/chmduquesne/rollinghash/adler32/adler32.go @@ -31,7 +31,7 @@ type digest struct { func (d *digest) Reset() { d.a = 1 d.b = 0 - d.window = nil + d.window = d.window[:0] d.oldest = 0 } @@ -55,9 +55,13 @@ func (d *digest) BlockSize() int { return 1 } // Write (via the embedded io.Writer interface) adds more data to the // running hash. It never returns an error. func (d *digest) Write(p []byte) (int, error) { - // Copy the window + // Copy the window, avoiding allocations where possible if len(d.window) != len(p) { - d.window = make([]byte, len(p)) + if cap(d.window) >= len(p) { + d.window = d.window[:len(p)] + } else { + d.window = make([]byte, len(p)) + } } copy(d.window, p)