codeberg.org/gruf/go-cache/v3@v3.5.7/result/pool.go (about) 1 package result 2 3 import "sync" 4 5 // resultPool is a global pool for result 6 // objects, regardless of cache type. 7 var resultPool sync.Pool 8 9 // getEntry fetches a result from pool, or allocates new. 10 func getResult() *result { 11 v := resultPool.Get() 12 if v == nil { 13 return new(result) 14 } 15 return v.(*result) 16 } 17 18 // putResult replaces a result in the pool. 19 func putResult(r *result) { 20 r.PKey = 0 21 r.Keys = nil 22 r.Value = nil 23 r.Error = nil 24 resultPool.Put(r) 25 }