Bugfix for parsekit.read: when filling the buffer, the read offset was not taken into account for determining how many bytes could be read.
This commit is contained in:
parent
3f9c745ac4
commit
31055a3cd3
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue