mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:04:02 +03:00
Remove redundant copyBufferPool from relay
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
package relay
|
|
||||||
|
|
||||||
import "sync"
|
|
||||||
|
|
||||||
var copyBufferPool = sync.Pool{
|
|
||||||
New: func() any {
|
|
||||||
rv := make([]byte, copyBufferSize)
|
|
||||||
|
|
||||||
return &rv
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func acquireCopyBuffer() *[]byte {
|
|
||||||
return copyBufferPool.Get().(*[]byte) //nolint: forcetypeassert
|
|
||||||
}
|
|
||||||
|
|
||||||
func releaseCopyBuffer(buf *[]byte) {
|
|
||||||
copyBufferPool.Put(buf)
|
|
||||||
}
|
|
||||||
@@ -35,13 +35,12 @@ func Relay(ctx context.Context, log Logger, telegramConn, clientConn essentials.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pump(log Logger, src, dst essentials.Conn, direction string) {
|
func pump(log Logger, src, dst essentials.Conn, direction string) {
|
||||||
|
var buf [copyBufferSize]byte
|
||||||
|
|
||||||
defer src.CloseRead() //nolint: errcheck
|
defer src.CloseRead() //nolint: errcheck
|
||||||
defer dst.CloseWrite() //nolint: errcheck
|
defer dst.CloseWrite() //nolint: errcheck
|
||||||
|
|
||||||
copyBuffer := acquireCopyBuffer()
|
n, err := io.CopyBuffer(src, dst, buf[:])
|
||||||
defer releaseCopyBuffer(copyBuffer)
|
|
||||||
|
|
||||||
n, err := io.CopyBuffer(src, dst, *copyBuffer)
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
|
|||||||
Reference in New Issue
Block a user