1
0
mirror of https://github.com/golang/go synced 2024-11-23 20:40:07 -07:00

reflect: use unsafe.String in name.name and name.tag

Change-Id: I9f54f1463b0682d0d76cd57e5fef318565883a87
Reviewed-on: https://go-review.googlesource.com/c/go/+/448675
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Tobias Klauser 2022-11-08 14:07:46 +01:00 committed by Gopher Robot
parent e5d2814576
commit 26b2c9a620

View File

@ -17,7 +17,6 @@ package reflect
import (
"internal/goarch"
"internal/unsafeheader"
"strconv"
"sync"
"unicode"
@ -525,27 +524,21 @@ func writeVarint(buf []byte, n int) int {
}
}
func (n name) name() (s string) {
func (n name) name() string {
if n.bytes == nil {
return
return ""
}
i, l := n.readVarint(1)
hdr := (*unsafeheader.String)(unsafe.Pointer(&s))
hdr.Data = unsafe.Pointer(n.data(1+i, "non-empty string"))
hdr.Len = l
return
return unsafe.String(n.data(1+i, "non-empty string"), l)
}
func (n name) tag() (s string) {
func (n name) tag() string {
if !n.hasTag() {
return ""
}
i, l := n.readVarint(1)
i2, l2 := n.readVarint(1 + i + l)
hdr := (*unsafeheader.String)(unsafe.Pointer(&s))
hdr.Data = unsafe.Pointer(n.data(1+i+l+i2, "non-empty string"))
hdr.Len = l2
return
return unsafe.String(n.data(1+i+l+i2, "non-empty string"), l2)
}
func (n name) pkgPath() string {