]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: use builtin min function in appendString
authorJes Cok <xigua67damn@gmail.com>
Fri, 21 Feb 2025 14:18:52 +0000 (14:18 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 25 Feb 2025 19:49:13 +0000 (11:49 -0800)
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>
src/encoding/json/encode.go

index d53e862d73bce9b8966212b1310bd68a5b7a11f7..7b4bfff70050f78b7ba0e6eed8e8f8c1524dac97 100644 (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]...)