encoding/json: use builtin min function in appendString

To make code a bit simpler.

Change-Id: Ic5f4a2357a757ad8fe391793a0eccb067a063e26
This commit is contained in:
Jes Cok 2025-02-21 22:05:46 +08:00
parent 64d82cd72c
commit 1369df6da1
1 changed files with 1 additions and 4 deletions

View File

@ -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]...)