mirror of
https://github.com/cheat/cheat.git
synced 2026-03-08 03:33:33 +01:00
- Bump Go from 1.19 to 1.26 and update all dependencies - Rewrite CI workflow with matrix strategy (Linux, macOS, Windows) - Update GitHub Actions to current versions (checkout@v4, setup-go@v5) - Update CodeQL actions from v1 to v3 - Fix cross-platform bug in mock/path.go (path.Join -> filepath.Join) - Clean up dependabot config (weekly schedule, remove stale ignore) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package sync
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
byteSlice = sync.Pool{
|
|
New: func() interface{} {
|
|
b := make([]byte, 16*1024)
|
|
return &b
|
|
},
|
|
}
|
|
bytesBuffer = sync.Pool{
|
|
New: func() interface{} {
|
|
return bytes.NewBuffer(nil)
|
|
},
|
|
}
|
|
)
|
|
|
|
// GetByteSlice returns a *[]byte that is managed by a sync.Pool.
|
|
// The initial slice length will be 16384 (16kb).
|
|
//
|
|
// After use, the *[]byte should be put back into the sync.Pool
|
|
// by calling PutByteSlice.
|
|
func GetByteSlice() *[]byte {
|
|
buf := byteSlice.Get().(*[]byte)
|
|
return buf
|
|
}
|
|
|
|
// PutByteSlice puts buf back into its sync.Pool.
|
|
func PutByteSlice(buf *[]byte) {
|
|
byteSlice.Put(buf)
|
|
}
|
|
|
|
// GetBytesBuffer returns a *bytes.Buffer that is managed by a sync.Pool.
|
|
// Returns a buffer that is reset and ready for use.
|
|
//
|
|
// After use, the *bytes.Buffer should be put back into the sync.Pool
|
|
// by calling PutBytesBuffer.
|
|
func GetBytesBuffer() *bytes.Buffer {
|
|
buf := bytesBuffer.Get().(*bytes.Buffer)
|
|
buf.Reset()
|
|
return buf
|
|
}
|
|
|
|
// PutBytesBuffer puts buf back into its sync.Pool.
|
|
func PutBytesBuffer(buf *bytes.Buffer) {
|
|
bytesBuffer.Put(buf)
|
|
}
|