aboutsummaryrefslogtreecommitdiff
path: root/libgo/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-06-19 15:13:53 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-06-19 15:13:53 +0000
commit4349775a30600906f5811ba7c743a5c22bdb3d7d (patch)
treea603f337ecccb290e61a1766664dd5ec30b5bb58 /libgo/go
parent7a907deeeb0b17ed332eb6e3a181a35b1873daf5 (diff)
downloadgcc-4349775a30600906f5811ba7c743a5c22bdb3d7d.zip
gcc-4349775a30600906f5811ba7c743a5c22bdb3d7d.tar.gz
gcc-4349775a30600906f5811ba7c743a5c22bdb3d7d.tar.bz2
compiler: optimize string concatenations
runtime.concatstring{2,3,4,5} are just wrappers of concatstrings. These wrappers don't provide any benefit, at least in the C calling convention we use, where passing arrays by value isn't an efficient thing. Change it to always use concatstrings. Also, the cap field of the slice passed to concatstrings is not necessary. So change it to pass a pointer and a length directly, which is more efficient than passing a slice header by value. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/182539 From-SVN: r272476
Diffstat (limited to 'libgo/go')
-rw-r--r--libgo/go/runtime/string.go24
1 files changed, 3 insertions, 21 deletions
diff --git a/libgo/go/runtime/string.go b/libgo/go/runtime/string.go
index eac94bf..9bcfc996 100644
--- a/libgo/go/runtime/string.go
+++ b/libgo/go/runtime/string.go
@@ -13,10 +13,6 @@ import (
// themselves, so that the compiler will export them.
//
//go:linkname concatstrings runtime.concatstrings
-//go:linkname concatstring2 runtime.concatstring2
-//go:linkname concatstring3 runtime.concatstring3
-//go:linkname concatstring4 runtime.concatstring4
-//go:linkname concatstring5 runtime.concatstring5
//go:linkname slicebytetostring runtime.slicebytetostring
//go:linkname slicebytetostringtmp runtime.slicebytetostringtmp
//go:linkname stringtoslicebyte runtime.stringtoslicebyte
@@ -38,7 +34,9 @@ type tmpBuf [tmpStringBufSize]byte
// If buf != nil, the compiler has determined that the result does not
// escape the calling function, so the string data can be stored in buf
// if small enough.
-func concatstrings(buf *tmpBuf, a []string) string {
+func concatstrings(buf *tmpBuf, p *string, n int) string {
+ var a []string
+ *(*slice)(unsafe.Pointer(&a)) = slice{unsafe.Pointer(p), n, n}
// idx := 0
l := 0
count := 0
@@ -73,22 +71,6 @@ func concatstrings(buf *tmpBuf, a []string) string {
return s
}
-func concatstring2(buf *tmpBuf, a [2]string) string {
- return concatstrings(buf, a[:])
-}
-
-func concatstring3(buf *tmpBuf, a [3]string) string {
- return concatstrings(buf, a[:])
-}
-
-func concatstring4(buf *tmpBuf, a [4]string) string {
- return concatstrings(buf, a[:])
-}
-
-func concatstring5(buf *tmpBuf, a [5]string) string {
- return concatstrings(buf, a[:])
-}
-
// Buf is a fixed-size buffer for the result,
// it is not nil if the result does not escape.
func slicebytetostring(buf *tmpBuf, b []byte) (str string) {