From db5d7d475e7e44a81a66ffe99a687c38b8c46ab7 Mon Sep 17 00:00:00 2001 From: Zhuowei Wang Date: Wed, 13 Nov 2024 10:37:02 +0800 Subject: [PATCH] Revert "perf: reuse buffer struct" This reverts commit cb7123236682f3a46ed3994d7790f0d056a93470. --- bufiox/defaultbuf.go | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/bufiox/defaultbuf.go b/bufiox/defaultbuf.go index a7fee85..0ef5587 100644 --- a/bufiox/defaultbuf.go +++ b/bufiox/defaultbuf.go @@ -17,7 +17,6 @@ package bufiox import ( "errors" "io" - "sync" "github.com/bytedance/gopkg/lang/dirtmake" "github.com/bytedance/gopkg/lang/mcache" @@ -44,30 +43,18 @@ const ( ) var errNegativeCount = errors.New("bufiox: negative count") -var defaultReaderPool sync.Pool -var bytesReaderPool sync.Pool // NewDefaultReader returns a new DefaultReader that reads from r. -func NewDefaultReader(rd io.Reader) (r *DefaultReader) { - v := defaultReaderPool.Get() - if v == nil { - r = &DefaultReader{} - } else { - r = v.(*DefaultReader) - } +func NewDefaultReader(rd io.Reader) *DefaultReader { + r := &DefaultReader{} r.reset(rd, nil) return r } // NewBytesReader returns a new DefaultReader that reads from buf[:len(buf)]. // Its operation on buf is read-only. -func NewBytesReader(buf []byte) (r *BytesReader) { - v := bytesReaderPool.Get() - if v == nil { - r = &BytesReader{} - } else { - r = v.(*BytesReader) - } +func NewBytesReader(buf []byte) *BytesReader { + r := &BytesReader{} r.reset(r.fakedIOReader, buf) return r } @@ -77,12 +64,6 @@ type BytesReader struct { fakedIOReader fakeIOReader } -func (r *BytesReader) Release(e error) error { - err := r.DefaultReader.Release(e) - bytesReaderPool.Put(r) - return err -} - func (r *DefaultReader) reset(rd io.Reader, buf []byte) { if cap(buf) > 0 { // set readOnly for buf from outside @@ -227,8 +208,6 @@ func (r *DefaultReader) Release(e error) error { } } r.ri = 0 - r.err = nil - defaultReaderPool.Put(r) return nil }