good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 641f4f5c authored by bestgopher's avatar bestgopher Committed by GitHub
Browse files

internal/bpool: add New function (#465)


Signed-off-by: default avatarbestgopher <84328409@qq.com>
parent 4ce1d904
No related branches found
No related tags found
No related merge requests found
...@@ -5,15 +5,16 @@ import ( ...@@ -5,15 +5,16 @@ import (
"sync" "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 // Get returns a buffer from the pool or creates a new one if
// the pool is empty. // the pool is empty.
func Get() *bytes.Buffer { func Get() *bytes.Buffer {
b := bpool.Get() b := bpool.Get()
if b == nil {
return &bytes.Buffer{}
}
return b.(*bytes.Buffer) return b.(*bytes.Buffer)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment