1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-18 17:00:26 +08:00

optimize(gold): apply more buffer pools

This commit is contained in:
源文雨
2024-07-15 01:22:12 +09:00
parent 32af3ce142
commit 17e1f6cac9
8 changed files with 152 additions and 71 deletions

View File

@@ -13,6 +13,19 @@ var bufferPool = sync.Pool{
},
}
func MakeBytes(sz int) []byte {
w := SelectWriter()
b := w.Bytes()
if cap(b) >= sz {
return b[:sz]
}
return make([]byte, sz)
}
func PutBytes(b []byte) {
PutWriter((*Writer)(bytes.NewBuffer(b)))
}
// SelectWriter 从池中取出一个 Writer
func SelectWriter() *Writer {
// 因为 bufferPool 定义有 New 函数