From: Jes Cok Date: Fri, 21 Feb 2025 14:18:52 +0000 (+0000) Subject: encoding/json: use builtin min function in appendString X-Git-Tag: go1.25rc1~917 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=97571f36103b045a7e9c15a92e9a35ab95fa6be5;p=gostls13.git 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 Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- 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]...)