]> Cypherpunks repositories - gostls13.git/commitdiff
time: optimize quote using byte(c) for ASCII
author1911860538 <alxps1911@gmail.com>
Thu, 13 Mar 2025 11:57:51 +0000 (11:57 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 14 Mar 2025 22:08:20 +0000 (15:08 -0700)
Since c < runeSelf && c >= ' ' (i.e., 32 <= c < 128), using buf = append(buf, byte(c)) instead of buf = append(buf, string(c)...) is a better choice, as it provides better performance.

Change-Id: Ic0ab25c71634a1814267f4d85be2ebd8a3d44676
GitHub-Last-Rev: 5445b547712bbfc77a5c17d76194291c22eb4a05
GitHub-Pull-Request: golang/go#72820
Reviewed-on: https://go-review.googlesource.com/c/go/+/657055
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/time/format.go

index da1bac5ac30d5819c2726312e5b4440e53345b14..87e990d48a4fa0548af6d67952fcf1f7e3a18e0b 100644 (file)
@@ -891,7 +891,7 @@ func quote(s string) string {
                        if c == '"' || c == '\\' {
                                buf = append(buf, '\\')
                        }
-                       buf = append(buf, string(c)...)
+                       buf = append(buf, byte(c))
                }
        }
        buf = append(buf, '"')