Browse Source

codec: do not create Selfer for types which already have implemented Selfer

Update #142
Ugorji Nwoke 9 years ago
parent
commit
5d64d76d3a
1 changed files with 10 additions and 0 deletions
  1. 10 0
      codec/gen.go

+ 10 - 0
codec/gen.go

@@ -164,6 +164,16 @@ type genRunner struct {
 //
 //
 // Library users: *DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.*
 // Library users: *DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.*
 func Gen(w io.Writer, buildTags, pkgName, uid string, useUnsafe bool, ti *TypeInfos, typ ...reflect.Type) {
 func Gen(w io.Writer, buildTags, pkgName, uid string, useUnsafe bool, ti *TypeInfos, typ ...reflect.Type) {
+	// trim out all types which already implement Selfer
+	typ2 := make([]reflect.Type, 0, len(typ))
+	for _, t := range typ {
+		if reflect.PtrTo(t).Implements(selferTyp) || t.Implements(selferTyp) {
+			continue
+		}
+		typ2 = append(typ2, t)
+	}
+	typ = typ2
+
 	if len(typ) == 0 {
 	if len(typ) == 0 {
 		return
 		return
 	}
 	}