aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/string.go
diff options
context:
space:
mode:
authorMartin Möhrmann <martisch@uos.de>2016-09-10 22:44:00 +0200
committerMartin Möhrmann <martisch@uos.de>2016-09-14 21:58:14 +0000
commit150de948eeceac0ace02a0f93a9a7a1f7421d744 (patch)
tree8888a2484e6817a6db428f27a3cac9ffb130d16c /src/runtime/string.go
parent1c5ac0827d2d0d2f5fb3b7f2b34b37e170beff1d (diff)
downloadgo-150de948eeceac0ace02a0f93a9a7a1f7421d744.tar.gz
go-150de948eeceac0ace02a0f93a9a7a1f7421d744.zip
cmd/compile: intrinsify slicebytetostringtmp when not instrumenting
when not instrumenting: - Intrinsify uses of slicebytetostringtmp within the runtime package in the ssa backend. - Pass OARRAYBYTESTRTMP nodes to the compiler backends for lowering instead of generating calls to slicebytetostringtmp. name old time/op new time/op delta ConcatStringAndBytes-4 27.9ns ± 2% 24.7ns ± 2% -11.52% (p=0.000 n=43+43) Fixes #17044 Change-Id: I51ce9c3b93284ce526edd0234f094e98580faf2d Reviewed-on: https://go-review.googlesource.com/29017 Run-TryBot: Martin Möhrmann <martisch@uos.de> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/string.go')
-rw-r--r--src/runtime/string.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/runtime/string.go b/src/runtime/string.go
index 2263e16410..4c4b736c63 100644
--- a/src/runtime/string.go
+++ b/src/runtime/string.go
@@ -109,17 +109,20 @@ func rawstringtmp(buf *tmpBuf, l int) (s string, b []byte) {
return
}
+// slicebytetostringtmp returns a "string" referring to the actual []byte bytes.
+//
+// Callers need to ensure that the returned string will not be used after
+// the calling goroutine modifies the original slice or synchronizes with
+// another goroutine.
+//
+// The function is only called when instrumenting
+// and otherwise intrinsified by the compiler.
+//
+// Some internal compiler optimizations use this function.
+// - Used for m[string(k)] lookup where m is a string-keyed map and k is a []byte.
+// - Used for "<"+string(b)+">" concatenation where b is []byte.
+// - Used for string(b)=="foo" comparison where b is []byte.
func slicebytetostringtmp(b []byte) string {
- // Return a "string" referring to the actual []byte bytes.
- // This is only for use by internal compiler optimizations
- // that know that the string form will be discarded before
- // the calling goroutine could possibly modify the original
- // slice or synchronize with another goroutine.
- // First such case is a m[string(k)] lookup where
- // m is a string-keyed map and k is a []byte.
- // Second such case is "<"+string(b)+">" concatenation where b is []byte.
- // Third such case is string(b)=="foo" comparison where b is []byte.
-
if raceenabled && len(b) > 0 {
racereadrangepc(unsafe.Pointer(&b[0]),
uintptr(len(b)),