Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Oct 19, 2021
1 parent 6c7005b commit 7828a36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
17 changes: 7 additions & 10 deletions bytes/buffer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*
* Copyright 2009 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
Expand Down Expand Up @@ -38,7 +38,6 @@ const smallBufferSize = 64
// The zero value for Buffer is an empty buffer ready to use.
type Buffer struct {
buf []byte // contents are the bytes buf[off : len(buf)]
peekBuf []byte // buf's temporary pointer
off int // read at &buf[off], write at &buf[len(buf)]
lastRead readOp // last read operation, so that Unread* can work correctly.
}
Expand Down Expand Up @@ -203,7 +202,6 @@ func (b *Buffer) WriteNextBegin(n int) []byte {
m = b.grow(n)
}

b.peekBuf = b.buf
extra := b.buf[m:]
b.buf = b.buf[:m]

Expand All @@ -215,16 +213,15 @@ func (b *Buffer) WriteNextEnd(n int) (int, error) {
if n < 0 {
return 0, nil
}
peekBufLen := len(b.peekBuf)
peekBufLen := cap(b.buf)
bufLen := len(b.buf)
l := bufLen + n
if l > peekBufLen || b.peekBuf == nil {
if l > peekBufLen {
return 0, fmt.Errorf("U have not invoked @WriteNextBegin")
}

b.lastRead = opInvalid
b.buf = b.peekBuf[:l]
b.peekBuf = nil
b.buf = b.buf[:l]

return n, nil
}
Expand Down
10 changes: 4 additions & 6 deletions bytes/buffer_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*
* Copyright 2009 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
Expand Down Expand Up @@ -39,7 +39,6 @@ func TestBufferWithPeek(t *testing.T) {
assert.True(t, b.lastRead == b1.lastRead)
assert.True(t, len(b.buf) == len(b1.buf))
assert.True(t, cap(b.buf) < cap(b1.buf))
assert.NotNil(t, b1.peekBuf)

// out of range
l, err := b1.WriteNextEnd(101)
Expand All @@ -49,6 +48,5 @@ func TestBufferWithPeek(t *testing.T) {
l, err = b1.WriteNextEnd(99)
assert.Nil(t, err)
assert.True(t, l == 99)
assert.Nil(t, b1.peekBuf)
assert.NotNil(t, b1.buf)
}

0 comments on commit 7828a36

Please sign in to comment.