]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: minor string/rune optimizations
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 14 Aug 2016 01:12:21 +0000 (18:12 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 22 Aug 2016 15:19:31 +0000 (15:19 +0000)
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: Martin Möhrmann <martisch@uos.de>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/rune.go
src/runtime/string.go

index 99c38e0bd91b7ab96d96b788400bf21833fe99cd..91a0ca25038a49a50889fc91c00bfeb97b386c9d 100644 (file)
@@ -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))
index ef28ba98284959bd735df2df33982af0c7feb19b..e74947f42f6eb1c3047b27b742d96680ac6fa06b 100644 (file)
@@ -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
 }