github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/xstring/buffer.go (about)

     1  package xstring
     2  
     3  import (
     4  	"bytes"
     5  	"sync"
     6  )
     7  
     8  type buffer struct {
     9  	bytes.Buffer
    10  }
    11  
    12  var buffersPool = sync.Pool{New: func() interface{} {
    13  	return &buffer{}
    14  }}
    15  
    16  func (b *buffer) Free() {
    17  	b.Reset()
    18  	buffersPool.Put(b)
    19  }
    20  
    21  func Buffer() *buffer {
    22  	return buffersPool.Get().(*buffer)
    23  }