mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package quicktemplate
|
|
|
|
import (
|
|
"github.com/valyala/bytebufferpool"
|
|
)
|
|
|
|
// ByteBuffer implements io.Writer on top of byte slice.
|
|
//
|
|
// Recycle byte buffers via AcquireByteBuffer and ReleaseByteBuffer
|
|
// in order to reduce memory allocations.
|
|
//
|
|
// Deprecated: use github.com/valyala/bytebufferpool instead.
|
|
type ByteBuffer bytebufferpool.ByteBuffer
|
|
|
|
// Write implements io.Writer.
|
|
func (b *ByteBuffer) Write(p []byte) (int, error) {
|
|
return bb(b).Write(p)
|
|
}
|
|
|
|
// Reset resets the byte buffer.
|
|
func (b *ByteBuffer) Reset() {
|
|
bb(b).Reset()
|
|
}
|
|
|
|
// AcquireByteBuffer returns new ByteBuffer from the pool.
|
|
//
|
|
// Return unneeded buffers to the pool by calling ReleaseByteBuffer
|
|
// in order to reduce memory allocations.
|
|
func AcquireByteBuffer() *ByteBuffer {
|
|
return (*ByteBuffer)(byteBufferPool.Get())
|
|
}
|
|
|
|
// ReleaseByteBuffer retruns byte buffer to the pool.
|
|
//
|
|
// Do not access byte buffer after returning it to the pool,
|
|
// otherwise data races may occur.
|
|
func ReleaseByteBuffer(b *ByteBuffer) {
|
|
byteBufferPool.Put(bb(b))
|
|
}
|
|
|
|
func bb(b *ByteBuffer) *bytebufferpool.ByteBuffer {
|
|
return (*bytebufferpool.ByteBuffer)(b)
|
|
}
|
|
|
|
var byteBufferPool bytebufferpool.Pool
|