pquerna / ffjson

faster JSON serialization for Go
Apache License 2.0
2.97k stars 234 forks source link

add BytesCopy and StringCopy #265

Open zhuzhu67373 opened 1 year ago

zhuzhu67373 commented 1 year ago

Bytes() and String() cannot be used when using fflib.Buffer in sync.Pool , like:


var bufPool = sync.Pool{
    New: func() interface{} {
        return fflib.NewBuffer([]byte{})
    },
}

func GetBuf() *fflib.Buffer {
    return bufPool.Get().(*fflib.Buffer)
}

func PutBuf(buf *fflib.Buffer) {
    buf.Reset()
    bufPool.Put(buf)
}

So I add copy version of Bytes() and String()