From: Josh Bleecher Snyder Date: Sun, 14 Aug 2016 01:12:21 +0000 (-0700) Subject: runtime: minor string/rune optimizations X-Git-Tag: go1.8beta1~1735 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=880c967ccd71013253a751452a83e6c6a0cf86df;p=gostls13.git runtime: minor string/rune optimizations Eliminate a spill in concatstrings. Provide bounds elim hints in runetochar. No significant benchmark movement. Before: "".runetochar t=1 size=412 args=0x28 locals=0x0 "".concatstrings t=1 size=736 args=0x30 locals=0x98 After: "".runetochar t=1 size=337 args=0x28 locals=0x0 "".concatstrings t=1 size=711 args=0x30 locals=0x90 Change-Id: Icce646976cb20a223163b7e72a54761193ac17e3 Reviewed-on: https://go-review.googlesource.com/27460 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Martin Möhrmann TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/rune.go b/src/runtime/rune.go index 99c38e0bd9..91a0ca2503 100644 --- a/src/runtime/rune.go +++ b/src/runtime/rune.go @@ -178,6 +178,7 @@ func runetochar(str []byte, r rune) int { * 0080-07FF => t2 tx */ if c <= rune2 { + _ = str[1] str[0] = byte(t2 | (c >> (1 * bitx))) str[1] = byte(tx | (c & maskx)) return 2 @@ -201,6 +202,7 @@ func runetochar(str []byte, r rune) int { * 0800-FFFF => t3 tx tx */ if c <= rune3 { + _ = str[2] str[0] = byte(t3 | (c >> (2 * bitx))) str[1] = byte(tx | ((c >> (1 * bitx)) & maskx)) str[2] = byte(tx | (c & maskx)) @@ -211,6 +213,7 @@ func runetochar(str []byte, r rune) int { * four character sequence (21-bit value) * 10000-1FFFFF => t4 tx tx tx */ + _ = str[3] str[0] = byte(t4 | (c >> (3 * bitx))) str[1] = byte(tx | ((c >> (2 * bitx)) & maskx)) str[2] = byte(tx | ((c >> (1 * bitx)) & maskx)) diff --git a/src/runtime/string.go b/src/runtime/string.go index ef28ba9828..e74947f42f 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -47,10 +47,9 @@ func concatstrings(buf *tmpBuf, a []string) string { return a[idx] } s, b := rawstringtmp(buf, l) - l = 0 for _, x := range a { - copy(b[l:], x) - l += len(x) + copy(b, x) + b = b[len(x):] } return s }