From f72ecf49ed40e8f412b14caca470089c3e66c1ec Mon Sep 17 00:00:00 2001 From: Pierre Durand Date: Thu, 15 Aug 2024 07:58:28 +0200 Subject: [PATCH] errstack: use syncutil.PoolFor --- errstack/errstack.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/errstack/errstack.go b/errstack/errstack.go index 56cbcfa..bdcf2f7 100644 --- a/errstack/errstack.go +++ b/errstack/errstack.go @@ -6,11 +6,11 @@ import ( "io" "path/filepath" "runtime" - "sync" "github.com/pierrre/errors/errbase" "github.com/pierrre/errors/erriter" "github.com/pierrre/go-libs/strconvio" + "github.com/pierrre/go-libs/syncutil" ) // Wrap adds a stack to an error. @@ -117,16 +117,17 @@ func has(err error) bool { const callersMaxLength = 1 << 16 -var callersPool = sync.Pool{ - New: func() any { - return make([]uintptr, callersMaxLength) +var callersPool = syncutil.PoolFor[[]uintptr]{ + New: func() *[]uintptr { + v := make([]uintptr, callersMaxLength) + return &v }, } func callers(skip int) []uintptr { - pcItf := callersPool.Get() - defer callersPool.Put(pcItf) - pc := pcItf.([]uintptr) //nolint:forcetypeassert // The pool only contains []uintptr. + pcp := callersPool.Get() + defer callersPool.Put(pcp) + pc := *pcp n := runtime.Callers(skip+2, pc) pcRes := make([]uintptr, n) copy(pcRes, pc)