diff options
| author | Joe Tsai <joetsai@digital-static.net> | 2023-03-11 12:03:28 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-03-15 15:41:55 +0000 |
| commit | 2e51f6f25cfc37f1e1d6fd3a90f0570979939a21 (patch) | |
| tree | bae827c86ba9b00aedce29e5331c6e973400eff7 /src/encoding/json/encode.go | |
| parent | e64e000f5561a37cbfae1e9e48d516d93934c91b (diff) | |
| download | go-2e51f6f25cfc37f1e1d6fd3a90f0570979939a21.tar.xz | |
encoding/json: make use of Buffer.AvailableBuffer
Use the explicit API for acquiring an empty available buffer,
rather than the hack that's implemented in terms of Bytes and Len.
Change-Id: If286ed42693acd61ffe28dc849ed4b76c3ae4434
Reviewed-on: https://go-review.googlesource.com/c/go/+/476337
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/encoding/json/encode.go')
| -rw-r--r-- | src/encoding/json/encode.go | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index f3c824d13e..79a82cfe75 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -259,10 +259,6 @@ type encodeState struct { ptrSeen map[any]struct{} } -func (e *encodeState) AvailableBuffer() []byte { - return availableBuffer(&e.Buffer) -} - const startDetectingCyclesAfter = 1000 var encodeStatePool sync.Pool @@ -445,7 +441,7 @@ func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { b, err := m.MarshalJSON() if err == nil { e.Grow(len(b)) - out := availableBuffer(&e.Buffer) + out := e.AvailableBuffer() out, err = appendCompact(out, b, opts.escapeHTML) e.Buffer.Write(out) } @@ -464,7 +460,7 @@ func addrMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { b, err := m.MarshalJSON() if err == nil { e.Grow(len(b)) - out := availableBuffer(&e.Buffer) + out := e.AvailableBuffer() out, err = appendCompact(out, b, opts.escapeHTML) e.Buffer.Write(out) } |
