diff --git a/runes/reader.go b/runes/reader.go index cb23d9e..1e73048 100644 --- a/runes/reader.go +++ b/runes/reader.go @@ -87,12 +87,12 @@ func (b *Reader) needsBytes(n int) error { func (b *Reader) rebuffer(size int) { var src, dst []byte - if size <= cap(b.buf) { - // same buffer - dst = b.buf - } else { + if size > cap(b.buf) { // new buffer dst = make([]byte, size) + } else { + // same buffer + dst = b.buf } src = b.buf[b.off:] @@ -106,16 +106,7 @@ func (b *Reader) rebuffer(size int) { } func (b *Reader) prepareBuffer(n int) { - available := b.available() - - switch { - case n <= available: - // n or more already available - case n <= available+b.off: - // rebase is enough - b.rebuffer(0) - default: - // resize + if n > b.available() { needed := len(b.buf) + n - b.off size := cap(b.buf)