diff --git a/read/read.go b/read/read.go index 8ff6c72..e35a9b9 100644 --- a/read/read.go +++ b/read/read.go @@ -126,7 +126,6 @@ func (buf *Buffer) RuneAt(offset int) (rune, int, error) { return utf8.RuneError, 0, buf.err } r, w := utf8.DecodeRune(buf.buffer[buf.start+offset:]) - return r, w, nil } @@ -166,7 +165,8 @@ func (buf *Buffer) fill(minBytes int) { // This is more efficient than only filling the data up to the point where // we can read the data at the 'minBytes' position. Ideally, the buffer is // filled completely with data to work with. - for buf.len < buf.cap { + availableLen := buf.cap - buf.start + for buf.len < availableLen { // Read bytes from our source, and append them to the end of the // current buffer data. n, err := buf.bufio.Read(buf.buffer[buf.len:buf.cap]) @@ -193,6 +193,7 @@ func (buf *Buffer) grow(minBytes int) { if buf.start > 0 && minBytes <= buf.cap { copy(buf.buffer, buf.buffer[buf.start:buf.start+buf.len]) buf.start = 0 + return } // Grow the buffer store by allocating a new one and copying the data.