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

optimize(orbyte): use manual destroy

This commit is contained in:
源文雨
2025-04-04 01:26:37 +09:00
parent 82c6136782
commit b5992574ec
16 changed files with 83 additions and 28 deletions

View File

@@ -47,6 +47,7 @@ func (p *Packet) PreCRC64() (crc uint64) {
)
}
})
w.Destroy()
return
}
@@ -58,11 +59,13 @@ func (p *Packet) WriteHeaderTo(buf *bytes.Buffer) {
buf.Write((*[PacketHeadNoCRCLen]byte)(
(unsafe.Pointer)(p),
)[:])
pbuf.NewBytes(buf.Len()).V(func(b []byte) {
b := pbuf.NewBytes(buf.Len())
b.V(func(b []byte) {
copy(b, buf.Bytes())
ClearTTL(b)
p.md5h8 = algo.MD5Hash8(b)
})
b.ManualDestroy()
_ = binary.Write(buf, binary.LittleEndian, p.md5h8)
return
}
@@ -76,14 +79,17 @@ func (p *Packet) WriteHeaderTo(buf *bytes.Buffer) {
w.Write(p.src[:])
w.Write(p.dst[:])
w.P(func(buf *pbuf.Buffer) {
pbuf.NewBytes(buf.Len()).V(func(b []byte) {
b := pbuf.NewBytes(buf.Len())
b.V(func(b []byte) {
copy(b, buf.Bytes())
ClearTTL(b)
p.md5h8 = algo.MD5Hash8(b)
})
b.ManualDestroy()
})
w.WriteUInt64(p.md5h8)
w.P(func(b *pbuf.Buffer) {
_, _ = buf.ReadFrom(b)
})
w.Destroy()
}