github.com/quay/claircore@v1.5.28/java/pool.go (about) 1 package java 2 3 import ( 4 "bytes" 5 "sync" 6 ) 7 8 // Pool is a pool of bytes.Buffers for Scan. 9 // 10 // Buffers returned by getBuf have a minimum size of 4MiB to reduce 11 // reallocations. 12 var pool sync.Pool 13 14 func getBuf() *bytes.Buffer { 15 const startSize = 4 * 1024 * 1024 // 4 MiB 16 if b, ok := pool.Get().(*bytes.Buffer); ok { 17 return b 18 } 19 var b bytes.Buffer 20 b.Grow(startSize) 21 return &b 22 } 23 24 func putBuf(b *bytes.Buffer) { 25 b.Reset() 26 pool.Put(b) 27 }