1
0
mirror of https://github.com/golang/go synced 2024-09-29 03:34:33 -06:00

internal/reflectlite: use unsafe.String in name.name and name.tag

Same as CL 448675 did in package reflect.

Change-Id: I26277d8dcf2d2e204724d6fa5cc6e1ad391633f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/448936
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Tobias Klauser 2022-11-09 11:09:42 +01:00 committed by Gopher Robot
parent 1309f0c51d
commit 3fc8ed2543

View File

@ -6,10 +6,7 @@
// any package except for "runtime" and "unsafe". // any package except for "runtime" and "unsafe".
package reflectlite package reflectlite
import ( import "unsafe"
"internal/unsafeheader"
"unsafe"
)
// Type is the representation of a Go type. // Type is the representation of a Go type.
// //
@ -341,27 +338,21 @@ func (n name) readVarint(off int) (int, int) {
} }
} }
func (n name) name() (s string) { func (n name) name() string {
if n.bytes == nil { if n.bytes == nil {
return return ""
} }
i, l := n.readVarint(1) i, l := n.readVarint(1)
hdr := (*unsafeheader.String)(unsafe.Pointer(&s)) return unsafe.String(n.data(1+i, "non-empty string"), l)
hdr.Data = unsafe.Pointer(n.data(1+i, "non-empty string"))
hdr.Len = l
return
} }
func (n name) tag() (s string) { func (n name) tag() string {
if !n.hasTag() { if !n.hasTag() {
return "" return ""
} }
i, l := n.readVarint(1) i, l := n.readVarint(1)
i2, l2 := n.readVarint(1 + i + l) i2, l2 := n.readVarint(1 + i + l)
hdr := (*unsafeheader.String)(unsafe.Pointer(&s)) return unsafe.String(n.data(1+i+l+i2, "non-empty string"), l2)
hdr.Data = unsafe.Pointer(n.data(1+i+l+i2, "non-empty string"))
hdr.Len = l2
return
} }
func (n name) pkgPath() string { func (n name) pkgPath() string {