mirror of
https://github.com/pyihe/go-pkg.git
synced 2025-10-06 00:16:53 +08:00
feature(buffers): add buffers
This commit is contained in:
35
buffers/buffer.go
Normal file
35
buffers/buffer.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package buffers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//type ByteBuffer = bytebufferpool.ByteBuffer
|
||||
//
|
||||
//var (
|
||||
// Get = bytebufferpool.Get
|
||||
// Put = func(b *ByteBuffer) {
|
||||
// if b != nil {
|
||||
// bytebufferpool.Put(b)
|
||||
// }
|
||||
// }
|
||||
//)
|
||||
|
||||
var bp sync.Pool
|
||||
|
||||
func Get() *bytes.Buffer {
|
||||
buffer, ok := bp.Get().(*bytes.Buffer)
|
||||
if ok {
|
||||
return buffer
|
||||
}
|
||||
return &bytes.Buffer{}
|
||||
}
|
||||
|
||||
func Put(b *bytes.Buffer) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
b.Reset()
|
||||
bp.Put(b)
|
||||
}
|
@@ -5,18 +5,6 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/pyihe/go-pkg/errors"
|
||||
"github.com/valyala/bytebufferpool"
|
||||
)
|
||||
|
||||
type ByteBuffer = bytebufferpool.ByteBuffer
|
||||
|
||||
var (
|
||||
Get = bytebufferpool.Get
|
||||
Put = func(b *ByteBuffer) {
|
||||
if b != nil {
|
||||
bytebufferpool.Put(b)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func Int64(b []byte) (v int64, err error) {
|
||||
|
Reference in New Issue
Block a user