Commit 880c967c authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
Reviewed-by: default avatarMartin Möhrmann <martisch@uos.de>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent fa8a28d5
......@@ -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))
......
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment