]> Cypherpunks.ru repositories - gostls13.git/commitdiff
encoding/xml: use reflect.TypeFor for known types
authorIan Lance Taylor <iant@golang.org>
Mon, 31 Jul 2023 22:20:54 +0000 (15:20 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 1 Aug 2023 14:29:37 +0000 (14:29 +0000)
For #60088

Change-Id: Ib2589b994d304cca1f2e2081639959d80818ac7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/514639
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
src/encoding/xml/marshal.go
src/encoding/xml/read.go
src/encoding/xml/read_test.go
src/encoding/xml/typeinfo.go

index 0c3cc0dc3618a18958a61918f1ba34400860f197..e641148011dfcd978357a8f87e8e470117b2d7e0 100644 (file)
@@ -415,9 +415,9 @@ func (p *printer) popPrefix() {
 }
 
 var (
-       marshalerType     = reflect.TypeOf((*Marshaler)(nil)).Elem()
-       marshalerAttrType = reflect.TypeOf((*MarshalerAttr)(nil)).Elem()
-       textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
+       marshalerType     = reflect.TypeFor[Marshaler]()
+       marshalerAttrType = reflect.TypeFor[MarshalerAttr]()
+       textMarshalerType = reflect.TypeFor[encoding.TextMarshaler]()
 )
 
 // marshalValue writes one or more XML elements representing val.
index c1c843e4c07d242eaf7d55144fd4be69f9503326..e3f9a587dd97d7a151449d19e25b0019ad118785 100644 (file)
@@ -304,10 +304,10 @@ func (d *Decoder) unmarshalAttr(val reflect.Value, attr Attr) error {
 }
 
 var (
-       attrType            = reflect.TypeOf(Attr{})
-       unmarshalerType     = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
-       unmarshalerAttrType = reflect.TypeOf((*UnmarshalerAttr)(nil)).Elem()
-       textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
+       attrType            = reflect.TypeFor[Attr]()
+       unmarshalerType     = reflect.TypeFor[Unmarshaler]()
+       unmarshalerAttrType = reflect.TypeFor[UnmarshalerAttr]()
+       textUnmarshalerType = reflect.TypeFor[encoding.TextUnmarshaler]()
 )
 
 const (
index 3e85fca5c6f63b601efc3842ff85010c8c79ba57..ce9989429571312f5758eabb6e4408c3495b9e37 100644 (file)
@@ -326,10 +326,10 @@ type BadPathEmbeddedB struct {
 var badPathTests = []struct {
        v, e any
 }{
-       {&BadPathTestA{}, &TagPathError{reflect.TypeOf(BadPathTestA{}), "First", "items>item1", "Second", "items"}},
-       {&BadPathTestB{}, &TagPathError{reflect.TypeOf(BadPathTestB{}), "First", "items>item1", "Second", "items>item1>value"}},
-       {&BadPathTestC{}, &TagPathError{reflect.TypeOf(BadPathTestC{}), "First", "", "Second", "First"}},
-       {&BadPathTestD{}, &TagPathError{reflect.TypeOf(BadPathTestD{}), "First", "", "Second", "First"}},
+       {&BadPathTestA{}, &TagPathError{reflect.TypeFor[BadPathTestA](), "First", "items>item1", "Second", "items"}},
+       {&BadPathTestB{}, &TagPathError{reflect.TypeFor[BadPathTestB](), "First", "items>item1", "Second", "items>item1>value"}},
+       {&BadPathTestC{}, &TagPathError{reflect.TypeFor[BadPathTestC](), "First", "", "Second", "First"}},
+       {&BadPathTestD{}, &TagPathError{reflect.TypeFor[BadPathTestD](), "First", "", "Second", "First"}},
 }
 
 func TestUnmarshalBadPaths(t *testing.T) {
index 2f123fdbb48dbc48b1fd0429d66bfd82560741ac..12d3918760472f2d38bcd1329e8994342420bebb 100644 (file)
@@ -46,7 +46,7 @@ const (
 
 var tinfoMap sync.Map // map[reflect.Type]*typeInfo
 
-var nameType = reflect.TypeOf(Name{})
+var nameType = reflect.TypeFor[Name]()
 
 // getTypeInfo returns the typeInfo structure with details necessary
 // for marshaling and unmarshaling typ.