From 3fc8ed2543091693eca514b363fcdbbe5c7f2916 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 9 Nov 2022 11:09:42 +0100 Subject: [PATCH] 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 Run-TryBot: Ian Lance Taylor Auto-Submit: Tobias Klauser TryBot-Result: Gopher Robot Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor --- src/internal/reflectlite/type.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/internal/reflectlite/type.go b/src/internal/reflectlite/type.go index 21e3c1278d0..43440b11263 100644 --- a/src/internal/reflectlite/type.go +++ b/src/internal/reflectlite/type.go @@ -6,10 +6,7 @@ // any package except for "runtime" and "unsafe". package reflectlite -import ( - "internal/unsafeheader" - "unsafe" -) +import "unsafe" // 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 { - 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 {