Skip to content

Commit

Permalink
fix: didn't fully reuse buffer memory
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Oct 30, 2023
1 parent 53c974e commit 1895d9a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/encoder/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func NewStreamEncoder(w io.Writer) *StreamEncoder {

// Encode encodes interface{} as JSON to io.Writer
func (enc *StreamEncoder) Encode(val interface{}) (err error) {
out := newBytes()
buf := newBytes()
out := buf

/* encode into the buffer */
err = EncodeInto(&out, val, enc.Opts)
Expand Down Expand Up @@ -79,6 +80,6 @@ func (enc *StreamEncoder) Encode(val interface{}) (err error) {
}

free_bytes:
freeBytes(out)
freeBytes(buf)
return err
}

0 comments on commit 1895d9a

Please sign in to comment.