aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorJake Bailey <jacob.b.bailey@gmail.com>2025-05-12 20:39:54 -0700
committerCherry Mui <cherryyz@google.com>2025-05-21 20:20:31 -0700
commit27ff0f249c33fdfa9c8e17a0367b46561236f36c (patch)
tree49cc8d5460b3a20df4dccffb314d6270078da327 /test/codegen
parentd2db2372a2fd79d539719fa13422d83d6fdfcda1 (diff)
downloadgo-27ff0f249c33fdfa9c8e17a0367b46561236f36c.tar.xz
cmd/compile/internal/ssa: eliminate string copies for calls to unique.Make
unique.Make always copies strings passed into it, so it's safe to not copy byte slices converted to strings either. Handle this just like map accesses with string(b) as keys. This CL only handles unique.Make(string(b)), not nested cases like unique.Make([2]string{string(b1), string(b2)}); this could be done in a followup CL but the map lookup code in walk is sufficiently different than the call handling code that I didn't attempt it. (SSA is much easier). Fixes #71926 Change-Id: Ic2f82f2f91963d563b4ddb1282bd49fc40da8b85 Reviewed-on: https://go-review.googlesource.com/c/go/+/672135 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/unique.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/codegen/unique.go b/test/codegen/unique.go
new file mode 100644
index 0000000000..8ddc986c26
--- /dev/null
+++ b/test/codegen/unique.go
@@ -0,0 +1,24 @@
+// asmcheck
+
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package codegen
+
+import "unique"
+
+func BytesToHandle(b []byte) unique.Handle[string] {
+ // amd64:-`.*runtime\.slicebytetostring\(`
+ return unique.Make(string(b))
+}
+
+type Pair struct {
+ S1 string
+ S2 string
+}
+
+func BytesPairToHandle(b1, b2 []byte) unique.Handle[Pair] {
+ // TODO: should not copy b1 and b2.
+ return unique.Make(Pair{string(b1), string(b2)})
+}