Skip to content

Commit

Permalink
Revert "perf: reuse buffer struct"
Browse files Browse the repository at this point in the history
This reverts commit cb71232.
  • Loading branch information
joway committed Nov 18, 2024
1 parent d7b1b87 commit db5d7d4
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions bufiox/defaultbuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package bufiox
import (
"errors"
"io"
"sync"

"github.com/bytedance/gopkg/lang/dirtmake"
"github.com/bytedance/gopkg/lang/mcache"
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -227,8 +208,6 @@ func (r *DefaultReader) Release(e error) error {
}
}
r.ri = 0
r.err = nil
defaultReaderPool.Put(r)
return nil
}

Expand Down

0 comments on commit db5d7d4

Please sign in to comment.