source: code/trunk/vendor/nhooyr.io/websocket/internal/bpool/bpool.go@ 822

Last change on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 360 bytes
Line 
1package bpool
2
3import (
4 "bytes"
5 "sync"
6)
7
8var bpool sync.Pool
9
10// Get returns a buffer from the pool or creates a new one if
11// the pool is empty.
12func Get() *bytes.Buffer {
13 b := bpool.Get()
14 if b == nil {
15 return &bytes.Buffer{}
16 }
17 return b.(*bytes.Buffer)
18}
19
20// Put returns a buffer into the pool.
21func Put(b *bytes.Buffer) {
22 b.Reset()
23 bpool.Put(b)
24}
Note: See TracBrowser for help on using the repository browser.