From 13d6f54c91f35e322383c5cfb2c94e4754c3bc99 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sat, 25 Oct 2025 14:10:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E7=94=A8=E4=BA=8E=E5=85=BC=E5=AE=B9=20go-?= =?UTF-8?q?cqhttp=20=E6=93=8D=E4=BD=9C=20bufferPool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/binary/builder.go | 12 ++++++++++++ utils/binary/pool.go | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/utils/binary/builder.go b/utils/binary/builder.go index f3d062b6..e89ae5c1 100644 --- a/utils/binary/builder.go +++ b/utils/binary/builder.go @@ -1,6 +1,7 @@ package binary import ( + "bytes" "encoding/binary" "io" "math" @@ -45,6 +46,17 @@ func (b *Builder) ToBytes() (data []byte) { return } +func (b *Builder) Buffer() (buffer *bytes.Buffer) { + b.p(func(ub *pbuf.UserBuffer[teacfg]) { + buffer = &ub.Buffer + }) + return +} + +func (b *Builder) ManualDestroy() { + (*orbyte.Item[pbuf.UserBuffer[teacfg]])(b).ManualDestroy() +} + // Pack TLV with tea encryption if key is set // // GC 安全, 返回的数据在 Builder 被销毁之后仍能被正确读取, diff --git a/utils/binary/pool.go b/utils/binary/pool.go index d73c8cdf..484f8dc8 100644 --- a/utils/binary/pool.go +++ b/utils/binary/pool.go @@ -25,6 +25,11 @@ func NewBuilder(key ...byte) *Builder { return (*Builder)(b) } +// PutBuilder +func PutBuilder(b *Builder) { + b.ManualDestroy() +} + var gzipPool = sync.Pool{ New: func() any { buf := new(bytes.Buffer)