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

optimize: memory consumption

This commit is contained in:
源文雨
2025-05-13 00:59:05 +09:00
parent d65fc4dd71
commit df8f6affa3
19 changed files with 204 additions and 242 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/klauspost/compress/zstd"
)
func EncodeZstd(data []byte) pbuf.Bytes {
func EncodeZstd(data []byte) []byte {
return bin.SelectWriter().P(func(w *pbuf.Buffer) {
enc, err := zstd.NewWriter(w, zstd.WithEncoderLevel(zstd.SpeedFastest))
if err != nil {
@@ -23,19 +23,19 @@ func EncodeZstd(data []byte) pbuf.Bytes {
if err != nil {
panic(err)
}
}).ToBytes()
}).ToBytes().Copy().Ignore().Trans()
}
func DecodeZstd(data []byte) (b pbuf.Bytes, err error) {
func DecodeZstd(data []byte) (b []byte, err error) {
dec, err := zstd.NewReader(bytes.NewReader(data))
if err != nil {
return pbuf.Bytes{}, err
return
}
b = bin.SelectWriter().P(func(w *pbuf.Buffer) {
_, err = io.Copy(w, dec)
dec.Close()
}).ToBytes()
}).ToBytes().Copy().Ignore().Trans()
return
}