From 1369df6da16121c342a4e678efe3e5b082485b74 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Fri, 21 Feb 2025 22:05:46 +0800 Subject: [PATCH] encoding/json: use builtin min function in appendString To make code a bit simpler. Change-Id: Ic5f4a2357a757ad8fe391793a0eccb067a063e26 --- src/encoding/json/encode.go | 5 +---- 1 file changed, 1 insertion(+), 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]...)