aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json
diff options
context:
space:
mode:
authorJes Cok <xigua67damn@gmail.com>2025-02-21 14:18:52 +0000
committerGopher Robot <gobot@golang.org>2025-02-25 11:49:13 -0800
commit97571f36103b045a7e9c15a92e9a35ab95fa6be5 (patch)
tree29b3bc86c9923d2e7c123b55de19d7a129c32893 /src/encoding/json
parentf707e53fd52284e58b9ea5d7889ad360d34d5116 (diff)
downloadgo-97571f36103b045a7e9c15a92e9a35ab95fa6be5.tar.xz
encoding/json: use builtin min function in appendString
To make code a bit simpler. Change-Id: I59fca1d5760e304abd53873ecf9ca8b2903e02e8 GitHub-Last-Rev: 1369df6da16121c342a4e678efe3e5b082485b74 GitHub-Pull-Request: golang/go#71873 Reviewed-on: https://go-review.googlesource.com/c/go/+/651355 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/encoding/json')
-rw-r--r--src/encoding/json/encode.go5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go
index d53e862d73..7b4bfff700 100644
--- a/src/encoding/json/encode.go
+++ b/src/encoding/json/encode.go
@@ -1015,10 +1015,7 @@ func appendString[Bytes []byte | string](dst []byte, src Bytes, escapeHTML bool)
// For now, cast only a small portion of byte slices to a string
// so that it can be stack allocated. This slows down []byte slightly
// due to the extra copy, but keeps string performance roughly the same.
- n := len(src) - i
- if n > utf8.UTFMax {
- n = utf8.UTFMax
- }
+ n := min(len(src)-i, utf8.UTFMax)
c, size := utf8.DecodeRuneInString(string(src[i : i+n]))
if c == utf8.RuneError && size == 1 {
dst = append(dst, src[start:i]...)