Skip to content

Commit

Permalink
internal/bpool: add New function (#465)
Browse files Browse the repository at this point in the history
Signed-off-by: bestgopher <[email protected]>
  • Loading branch information
bestgopher authored Aug 21, 2024
1 parent 4ce1d90 commit 641f4f5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/bpool/bpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"sync"
)

var bpool sync.Pool
var bpool = sync.Pool{
New: func() any {
return &bytes.Buffer{}
},
}

// Get returns a buffer from the pool or creates a new one if
// the pool is empty.
func Get() *bytes.Buffer {
b := bpool.Get()
if b == nil {
return &bytes.Buffer{}
}
return b.(*bytes.Buffer)
}

Expand Down

0 comments on commit 641f4f5

Please sign in to comment.