From 9c9df65c539a0e2b1de9094382b87cc0f2748ae3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Thu, 10 Aug 2017 11:17:59 +0900 Subject: [PATCH] reflect: remove useless parameter from newName MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit pkgPath always received the empty string. Worse yet, it panicked if it received anything else. This has been the case ever since newName was introduced in early 2016. Change-Id: I5f164305bd30c34455ef35e776c7616f303b37e4 Reviewed-on: https://go-review.googlesource.com/54331 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: David Crawshaw --- src/reflect/export_test.go | 2 +- src/reflect/type.go | 29 +++++++++++------------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/reflect/export_test.go b/src/reflect/export_test.go index ffd1104487..e7a5ac343b 100644 --- a/src/reflect/export_test.go +++ b/src/reflect/export_test.go @@ -111,7 +111,7 @@ func IsExported(t Type) bool { } func ResolveReflectName(s string) { - resolveReflectName(newName(s, "", "", false)) + resolveReflectName(newName(s, "", false)) } type Buffer struct { diff --git a/src/reflect/type.go b/src/reflect/type.go index cbf4f73bf4..dbb65f14bf 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -531,7 +531,7 @@ func round(n, a uintptr) uintptr { return (n + a - 1) &^ (a - 1) } -func newName(n, tag, pkgPath string, exported bool) name { +func newName(n, tag string, exported bool) name { if len(n) > 1<<16-1 { panic("reflect.nameFrom: name too long: " + n) } @@ -548,9 +548,6 @@ func newName(n, tag, pkgPath string, exported bool) name { l += 2 + len(tag) bits |= 1 << 1 } - if pkgPath != "" { - bits |= 1 << 2 - } b := make([]byte, l) b[0] = bits @@ -564,10 +561,6 @@ func newName(n, tag, pkgPath string, exported bool) name { copy(tb[2:], tag) } - if pkgPath != "" { - panic("reflect: creating a name with a package path is not supported") - } - return name{bytes: &b[0]} } @@ -1436,7 +1429,7 @@ func (t *rtype) ptrTo() *rtype { prototype := *(**ptrType)(unsafe.Pointer(&iptr)) pp := *prototype - pp.str = resolveReflectName(newName(s, "", "", false)) + pp.str = resolveReflectName(newName(s, "", false)) pp.ptrToThis = 0 // For the type structures linked into the binary, the @@ -1849,7 +1842,7 @@ func ChanOf(dir ChanDir, t Type) Type { ch := *prototype ch.tflag = 0 ch.dir = uintptr(dir) - ch.str = resolveReflectName(newName(s, "", "", false)) + ch.str = resolveReflectName(newName(s, "", false)) ch.hash = fnv1(typ.hash, 'c', byte(dir)) ch.elem = typ @@ -1892,7 +1885,7 @@ func MapOf(key, elem Type) Type { // Make a map type. var imap interface{} = (map[unsafe.Pointer]unsafe.Pointer)(nil) mt := **(**mapType)(unsafe.Pointer(&imap)) - mt.str = resolveReflectName(newName(s, "", "", false)) + mt.str = resolveReflectName(newName(s, "", false)) mt.tflag = 0 mt.hash = fnv1(etyp.hash, 'm', byte(ktyp.hash>>24), byte(ktyp.hash>>16), byte(ktyp.hash>>8), byte(ktyp.hash)) mt.key = ktyp @@ -2060,7 +2053,7 @@ func FuncOf(in, out []Type, variadic bool) Type { } // Populate the remaining fields of ft and store in cache. - ft.str = resolveReflectName(newName(str, "", "", false)) + ft.str = resolveReflectName(newName(str, "", false)) ft.ptrToThis = 0 return addToCache(&ft.rtype) } @@ -2255,7 +2248,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype { b.align = 8 } s := "bucket(" + ktyp.String() + "," + etyp.String() + ")" - b.str = resolveReflectName(newName(s, "", "", false)) + b.str = resolveReflectName(newName(s, "", false)) return b } @@ -2285,7 +2278,7 @@ func SliceOf(t Type) Type { prototype := *(**sliceType)(unsafe.Pointer(&islice)) slice := *prototype slice.tflag = 0 - slice.str = resolveReflectName(newName(s, "", "", false)) + slice.str = resolveReflectName(newName(s, "", false)) slice.hash = fnv1(typ.hash, '[') slice.elem = typ slice.ptrToThis = 0 @@ -2684,7 +2677,7 @@ func StructOf(fields []StructField) Type { } } - typ.str = resolveReflectName(newName(str, "", "", false)) + typ.str = resolveReflectName(newName(str, "", false)) typ.tflag = 0 typ.hash = hash typ.size = size @@ -2813,7 +2806,7 @@ func runtimeStructField(field StructField) structField { resolveReflectType(field.Type.common()) // install in runtime return structField{ - name: newName(field.Name, string(field.Tag), "", true), + name: newName(field.Name, string(field.Tag), true), typ: field.Type.common(), offsetAnon: offsetAnon, } @@ -2877,7 +2870,7 @@ func ArrayOf(count int, elem Type) Type { prototype := *(**arrayType)(unsafe.Pointer(&iarray)) array := *prototype array.tflag = 0 - array.str = resolveReflectName(newName(s, "", "", false)) + array.str = resolveReflectName(newName(s, "", false)) array.hash = fnv1(typ.hash, '[') for n := uint32(count); n > 0; n >>= 8 { array.hash = fnv1(array.hash, byte(n)) @@ -3130,7 +3123,7 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin } else { s = "funcargs(" + t.String() + ")" } - x.str = resolveReflectName(newName(s, "", "", false)) + x.str = resolveReflectName(newName(s, "", false)) // cache result for future callers framePool = &sync.Pool{New: func() interface{} { -- 2.50.0