mirror of
https://github.com/moby/buildkit.git
synced 2026-06-30 19:57:39 +00:00
refactor: add typed sync.Pool wrapper to eliminate any
Introduce util/pools.Pool[T] as a generic typed wrapper around sync.Pool. Migrate existing pool usages in contenthash, converter, and overlay packages to use the new wrapper, removing unchecked type assertions at each call site. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
13
cache/contenthash/checksum.go
vendored
13
cache/contenthash/checksum.go
vendored
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/moby/buildkit/session"
|
||||
"github.com/moby/buildkit/snapshot"
|
||||
"github.com/moby/buildkit/util/cachedigest"
|
||||
"github.com/moby/buildkit/util/pools"
|
||||
"github.com/moby/locker"
|
||||
"github.com/moby/patternmatcher"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
@@ -1261,15 +1262,13 @@ func ensureOriginMetadata(md cache.RefMetadata) cache.RefMetadata {
|
||||
return em
|
||||
}
|
||||
|
||||
var pool32K = sync.Pool{
|
||||
New: func() any {
|
||||
buf := make([]byte, 32*1024) // 32K
|
||||
return &buf
|
||||
},
|
||||
}
|
||||
var pool32K = pools.New(func() *[]byte {
|
||||
buf := make([]byte, 32*1024) // 32K
|
||||
return &buf
|
||||
})
|
||||
|
||||
func poolsCopy(dst io.Writer, src io.Reader) (written int64, err error) {
|
||||
buf := pool32K.Get().(*[]byte)
|
||||
buf := pool32K.Get()
|
||||
written, err = io.CopyBuffer(dst, src, *buf)
|
||||
pool32K.Put(buf)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user