From 7828a36fc8d671c4d66842f50464e0b21dcacdc0 Mon Sep 17 00:00:00 2001 From: AlexStocks Date: Tue, 19 Oct 2021 21:58:38 +0800 Subject: [PATCH] format --- bytes/buffer.go | 17 +++++++---------- bytes/buffer_test.go | 10 ++++------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/bytes/buffer.go b/bytes/buffer.go index 9ef8aea..623f88e 100644 --- a/bytes/buffer.go +++ b/bytes/buffer.go @@ -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. @@ -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. } @@ -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] @@ -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 } diff --git a/bytes/buffer_test.go b/bytes/buffer_test.go index ab2f9ad..6ec697a 100644 --- a/bytes/buffer_test.go +++ b/bytes/buffer_test.go @@ -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. @@ -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) @@ -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) }