Skip to content

Commit

Permalink
fix: check CanSizeReuse in FreeBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY authored and liuq19 committed Jul 9, 2024
1 parent 3a695bd commit cc6330c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/encoder/vars/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ func NewBuffer() *bytes.Buffer {
}

func FreeBytes(p *[]byte) {
(*p) = (*p)[:0]
bytesPool.Put(p)
if rt.CanSizeResue(cap(*p)) {
(*p) = (*p)[:0]
bytesPool.Put(p)
}
}

func FreeStack(p *Stack) {
Expand All @@ -129,8 +131,10 @@ func FreeStack(p *Stack) {
}

func FreeBuffer(p *bytes.Buffer) {
p.Reset()
bufferPool.Put(p)
if rt.CanSizeResue(cap(p.Bytes())) {
p.Reset()
bufferPool.Put(p)
}
}

var (
Expand Down

0 comments on commit cc6330c

Please sign in to comment.