diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-12-12 23:13:29 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-12-12 23:13:29 +0000 |
commit | a42a906c420d7bb196cb8541e0ab65264a0b04b0 (patch) | |
tree | 8c441679e35147b1e9bec048f733fc394fb0c161 /libgo/go/bytes/buffer.go | |
parent | bc77608b97abcc4bb3171f08a71e34ae342e9f8d (diff) | |
download | gcc-a42a906c420d7bb196cb8541e0ab65264a0b04b0.zip gcc-a42a906c420d7bb196cb8541e0ab65264a0b04b0.tar.gz gcc-a42a906c420d7bb196cb8541e0ab65264a0b04b0.tar.bz2 |
libgo: Update to current master library sources.
From-SVN: r194460
Diffstat (limited to 'libgo/go/bytes/buffer.go')
-rw-r--r-- | libgo/go/bytes/buffer.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/libgo/go/bytes/buffer.go b/libgo/go/bytes/buffer.go index efb9798..3ae9303 100644 --- a/libgo/go/bytes/buffer.go +++ b/libgo/go/bytes/buffer.go @@ -360,16 +360,24 @@ func (b *Buffer) UnreadByte() error { // ReadBytes returns err != nil if and only if the returned data does not end in // delim. func (b *Buffer) ReadBytes(delim byte) (line []byte, err error) { + slice, err := b.readSlice(delim) + // return a copy of slice. The buffer's backing array may + // be overwritten by later calls. + line = append(line, slice...) + return +} + +// readSlice is like readBytes but returns a reference to internal buffer data. +func (b *Buffer) readSlice(delim byte) (line []byte, err error) { i := IndexByte(b.buf[b.off:], delim) - size := i + 1 + end := b.off + i + 1 if i < 0 { - size = len(b.buf) - b.off + end = len(b.buf) err = io.EOF } - line = make([]byte, size) - copy(line, b.buf[b.off:]) - b.off += size - return + line = b.buf[b.off:end] + b.off = end + return line, err } // ReadString reads until the first occurrence of delim in the input, @@ -379,8 +387,8 @@ func (b *Buffer) ReadBytes(delim byte) (line []byte, err error) { // ReadString returns err != nil if and only if the returned data does not end // in delim. func (b *Buffer) ReadString(delim byte) (line string, err error) { - bytes, err := b.ReadBytes(delim) - return string(bytes), err + slice, err := b.readSlice(delim) + return string(slice), err } // NewBuffer creates and initializes a new Buffer using buf as its initial |