File: bytebuffer.go

package info (click to toggle)
golang-github-valyala-quicktemplate 1.8.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: makefile: 16; xml: 15
file content (45 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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