Skip to content

Commit

Permalink
encoding/json: use base64.Encoding.AppendEncode
Browse files Browse the repository at this point in the history
For #53693

Change-Id: I6a428a4a10a2e2efa03296f539e190f0743c1f46
Reviewed-on: https://go-review.googlesource.com/c/go/+/520755
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Joseph Tsai <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Auto-Submit: Dmitri Shuralyov <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Run-TryBot: Andy Pan <[email protected]>
  • Loading branch information
panjf2000 authored and gopherbot committed Aug 18, 2023
1 parent ce16086 commit 3419a0a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/encoding/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,15 +781,11 @@ func encodeByteSlice(e *encodeState, v reflect.Value, _ encOpts) {
e.WriteString("null")
return
}
s := v.Bytes()
encodedLen := base64.StdEncoding.EncodedLen(len(s))
e.Grow(len(`"`) + encodedLen + len(`"`))

// TODO(https://go.dev/issue/53693): Use base64.Encoding.AppendEncode.
s := v.Bytes()
b := e.AvailableBuffer()
b = append(b, '"')
base64.StdEncoding.Encode(b[len(b):][:encodedLen], s)
b = b[:len(b)+encodedLen]
b = base64.StdEncoding.AppendEncode(b, s)
b = append(b, '"')
e.Write(b)
}
Expand Down

0 comments on commit 3419a0a

Please sign in to comment.