Improve: use one bytes.Buffer pool

This commit is contained in:
Dreamacro
2021-09-20 21:02:18 +08:00
parent 5b1a0a523f
commit 70c8605cca
10 changed files with 53 additions and 60 deletions

View File

@ -1,10 +1,9 @@
package protocol
import (
"bytes"
"net"
"github.com/Dreamacro/clash/transport/ssr/tools"
"github.com/Dreamacro/clash/common/pool"
)
type PacketConn struct {
@ -13,9 +12,8 @@ type PacketConn struct {
}
func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (int, error) {
buf := tools.BufPool.Get().(*bytes.Buffer)
defer tools.BufPool.Put(buf)
defer buf.Reset()
buf := pool.GetBuffer()
defer pool.PutBuffer(buf)
err := c.EncodePacket(buf, b)
if err != nil {
return 0, err