From bda42a7a782dbcf4b123d617c5b60f3c848cbb82 Mon Sep 17 00:00:00 2001 From: Diogo Pinela Date: Thu, 5 Mar 2020 00:28:05 +0000 Subject: runtime: use staticuint64s instead of staticbytes for 1-length strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was the last remaining use of staticbytes, so we can now delete it. The new code appears slightly faster on amd64: name old time/op new time/op delta SliceByteToString/1-4 6.29ns ± 2% 5.89ns ± 1% -6.46% (p=0.000 n=14+14) This may not be the case on the big-endian architectures, since they have to do an extra addition. Updates #37612 Change-Id: Icb84c5911ba025f798de152849992a55be99e4f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/221979 Reviewed-by: Josh Bleecher Snyder Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot --- src/runtime/string.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/runtime/string.go') diff --git a/src/runtime/string.go b/src/runtime/string.go index 184245b105..7dc0bd789f 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -6,6 +6,7 @@ package runtime import ( "internal/bytealg" + "runtime/internal/sys" "unsafe" ) @@ -90,7 +91,11 @@ func slicebytetostring(buf *tmpBuf, b []byte) (str string) { msanread(unsafe.Pointer(&b[0]), uintptr(l)) } if l == 1 { - stringStructOf(&str).str = unsafe.Pointer(&staticbytes[b[0]]) + p := unsafe.Pointer(&staticuint64s[b[0]]) + if sys.BigEndian { + p = add(p, 7) + } + stringStructOf(&str).str = p stringStructOf(&str).len = 1 return } @@ -231,12 +236,6 @@ func stringStructOf(sp *string) *stringStruct { } func intstring(buf *[4]byte, v int64) (s string) { - if v >= 0 && v < runeSelf { - stringStructOf(&s).str = unsafe.Pointer(&staticbytes[v]) - stringStructOf(&s).len = 1 - return - } - var b []byte if buf != nil { b = buf[:] -- cgit v1.3