]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: remove useless parameter from newName
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 10 Aug 2017 02:17:59 +0000 (11:17 +0900)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 16 Aug 2017 15:11:03 +0000 (15:11 +0000)
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>
src/reflect/export_test.go
src/reflect/type.go

index ffd1104487ba2af8a8fb8cebfee7396d681f0bee..e7a5ac343ba929291df46bf9edbde59473205539 100644 (file)
@@ -111,7 +111,7 @@ func IsExported(t Type) bool {
 }
 
 func ResolveReflectName(s string) {
-       resolveReflectName(newName(s, "", "", false))
+       resolveReflectName(newName(s, "", false))
 }
 
 type Buffer struct {
index cbf4f73bf4def09ba7bb8b91fb2a535ffb360d62..dbb65f14bf36eeb52109c91bcc491e7fb56e35a7 100644 (file)
@@ -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{} {