mirror of
https://github.com/fumiama/orbyte.git
synced 2026-06-11 05:30:29 +08:00
init
This commit is contained in:
39
pbuf/pbuf.go
Normal file
39
pbuf/pbuf.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Package pbuf is a lightweight pooled buffer.
|
||||
package pbuf
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/fumiama/orbyte"
|
||||
)
|
||||
|
||||
var bufferPool = NewBufferPool()
|
||||
|
||||
type BufferPool struct {
|
||||
p *orbyte.Pool[bytes.Buffer]
|
||||
}
|
||||
|
||||
func NewBufferPool() BufferPool {
|
||||
return BufferPool{p: orbyte.NewPool[bytes.Buffer](bufpooler{})}
|
||||
}
|
||||
|
||||
// NewBuffer wraps bytes.NewBuffer
|
||||
func NewBuffer(buf []byte) *orbyte.Item[bytes.Buffer] {
|
||||
return bufferPool.NewBuffer(buf)
|
||||
}
|
||||
|
||||
// NewBytes alloc sz bytes.
|
||||
func NewBytes(sz int) Bytes {
|
||||
return bufferPool.NewBytes(sz)
|
||||
}
|
||||
|
||||
// InvolveBytes involve outside buf into pool.
|
||||
func InvolveBytes(b ...byte) Bytes {
|
||||
return bufferPool.InvolveBytes(b...)
|
||||
}
|
||||
|
||||
// ParseBytes convert outside bytes to Bytes safely
|
||||
// without adding it into pool.
|
||||
func ParseBytes(b ...byte) Bytes {
|
||||
return bufferPool.ParseBytes(b...)
|
||||
}
|
||||
Reference in New Issue
Block a user