1
0
mirror of https://github.com/fumiama/orbyte.git synced 2026-06-11 05:30:29 +08:00
This commit is contained in:
源文雨
2025-02-24 23:52:18 +09:00
parent 8f413ecfdf
commit eec7c4821d
12 changed files with 626 additions and 0 deletions

39
pbuf/pbuf.go Normal file
View 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...)
}