mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json/jsontext: use bytes.Buffer.AvailableBuffer
This logic was added in October, 2021:
0b3bd4e1ed
before the introduction of bytes.Buffer.AvailableBuffer in March, 2023.
https://go.dev/cl/474635
Updates #71845
Change-Id: I96800e1ba8fce15cc78316779db4ddcd4fe1d510
Reviewed-on: https://go-review.googlesource.com/c/go/+/685136
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
parent
6bd9944c9a
commit
86fca3dcb6
1 changed files with 1 additions and 1 deletions
|
|
@ -114,7 +114,7 @@ func (e *encoderState) reset(b []byte, w io.Writer, opts ...Options) {
|
||||||
e.state.reset()
|
e.state.reset()
|
||||||
e.encodeBuffer = encodeBuffer{Buf: b, wr: w, bufStats: e.bufStats}
|
e.encodeBuffer = encodeBuffer{Buf: b, wr: w, bufStats: e.bufStats}
|
||||||
if bb, ok := w.(*bytes.Buffer); ok && bb != nil {
|
if bb, ok := w.(*bytes.Buffer); ok && bb != nil {
|
||||||
e.Buf = bb.Bytes()[bb.Len():] // alias the unused buffer of bb
|
e.Buf = bb.AvailableBuffer() // alias the unused buffer of bb
|
||||||
}
|
}
|
||||||
opts2 := jsonopts.Struct{} // avoid mutating e.Struct in case it is part of opts
|
opts2 := jsonopts.Struct{} // avoid mutating e.Struct in case it is part of opts
|
||||||
opts2.Join(opts...)
|
opts2.Join(opts...)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue