From 854048b0ab8c8c7e94774413ff3f78906331259e Mon Sep 17 00:00:00 2001 From: Charlie Vieth Date: Fri, 21 Nov 2025 16:41:58 -0500 Subject: [PATCH] plugin/pkg/replacer: fix usage of sync.Pool to save an alloc (#7701) --- plugin/pkg/replacer/replacer.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugin/pkg/replacer/replacer.go b/plugin/pkg/replacer/replacer.go index 010ed259d..c402e0ade 100644 --- a/plugin/pkg/replacer/replacer.go +++ b/plugin/pkg/replacer/replacer.go @@ -257,12 +257,14 @@ func loadFormat(s string) replacer { // bufPool stores pointers to scratch buffers. var bufPool = sync.Pool{ New: func() any { - return make([]byte, 0, 256) + b := make([]byte, 0, 256) + return &b }, } func (r replacer) Replace(ctx context.Context, state request.Request, rr *dnstest.Recorder) string { - b := bufPool.Get().([]byte) + p := bufPool.Get().(*[]byte) + b := *p for _, s := range r { switch s.typ { case typeLabel: @@ -278,7 +280,7 @@ func (r replacer) Replace(ctx context.Context, state request.Request, rr *dnstes } } s := string(b) - //nolint:staticcheck - bufPool.Put(b[:0]) + *p = b[:0] + bufPool.Put(p) return s }