mirror of
https://github.com/coredns/coredns.git
synced 2025-11-23 12:14:02 -05:00
plugin/pkg/replacer: fix usage of sync.Pool to save an alloc (#7701)
This commit is contained in:
@@ -257,12 +257,14 @@ func loadFormat(s string) replacer {
|
|||||||
// bufPool stores pointers to scratch buffers.
|
// bufPool stores pointers to scratch buffers.
|
||||||
var bufPool = sync.Pool{
|
var bufPool = sync.Pool{
|
||||||
New: func() any {
|
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 {
|
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 {
|
for _, s := range r {
|
||||||
switch s.typ {
|
switch s.typ {
|
||||||
case typeLabel:
|
case typeLabel:
|
||||||
@@ -278,7 +280,7 @@ func (r replacer) Replace(ctx context.Context, state request.Request, rr *dnstes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
s := string(b)
|
s := string(b)
|
||||||
//nolint:staticcheck
|
*p = b[:0]
|
||||||
bufPool.Put(b[:0])
|
bufPool.Put(p)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user