]> Sergey Matveev's repositories - btrtrc.git/commitdiff
bencode: simplify getting `marshalerType` and `unmarshalerType` (#652)
authorYenForYang <YenForYang@users.noreply.github.com>
Sat, 18 Sep 2021 02:43:53 +0000 (21:43 -0500)
committerGitHub <noreply@github.com>
Sat, 18 Sep 2021 02:43:53 +0000 (12:43 +1000)
bencode/misc.go

index 38b7fce84fe55fe74009184b6e5b2c815e0cc663..2e9f1fac1d332a4ba39bbc6cb6d907d8e81deb40 100644 (file)
@@ -6,16 +6,10 @@ import (
 )
 
 // Wow Go is retarded.
-var marshalerType = reflect.TypeOf(func() *Marshaler {
-       var m Marshaler
-       return &m
-}()).Elem()
-
-// Wow Go is retarded.
-var unmarshalerType = reflect.TypeOf(func() *Unmarshaler {
-       var i Unmarshaler
-       return &i
-}()).Elem()
+var (
+       marshalerType   = reflect.TypeOf((*Marshaler)(nil)).Elem()
+       unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
+)
 
 func bytesAsString(b []byte) string {
        return *(*string)(unsafe.Pointer(&b))