Skip to content

Commit

Permalink
reflect: remove useless parameter from newName
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
  • Loading branch information
mvdan committed Aug 16, 2017
1 parent 2918652 commit 9c9df65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/reflect/export_test.go
Expand Up @@ -111,7 +111,7 @@ func IsExported(t Type) bool {
}

func ResolveReflectName(s string) {
resolveReflectName(newName(s, "", "", false))
resolveReflectName(newName(s, "", false))
}

type Buffer struct {
Expand Down
29 changes: 11 additions & 18 deletions src/reflect/type.go
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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]}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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{} {
Expand Down

0 comments on commit 9c9df65

Please sign in to comment.