Merge pull request #99 from erikdubbelboer/reuseslice

Reuse slices when possible
This commit is contained in:
Vasily Romanov
2017-02-16 16:17:51 +03:00
committed by GitHub
+8 -4
View File
@@ -106,10 +106,14 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field
fmt.Fprintln(g.out, ws+" "+out+" = nil")
fmt.Fprintln(g.out, ws+"} else {")
fmt.Fprintln(g.out, ws+" in.Delim('[')")
fmt.Fprintln(g.out, ws+" if !in.IsDelim(']') {")
fmt.Fprintln(g.out, ws+" "+out+" = make("+g.getType(t)+", 0, "+fmt.Sprint(capacity)+")")
fmt.Fprintln(g.out, ws+" } else {")
fmt.Fprintln(g.out, ws+" "+out+" = "+g.getType(t)+"{}")
fmt.Fprintln(g.out, ws+" if "+out+" == nil {")
fmt.Fprintln(g.out, ws+" if !in.IsDelim(']') {")
fmt.Fprintln(g.out, ws+" "+out+" = make("+g.getType(t)+", 0, "+fmt.Sprint(capacity)+")")
fmt.Fprintln(g.out, ws+" } else {")
fmt.Fprintln(g.out, ws+" "+out+" = "+g.getType(t)+"{}")
fmt.Fprintln(g.out, ws+" }")
fmt.Fprintln(g.out, ws+" } else { ")
fmt.Fprintln(g.out, ws+" "+out+" = ("+out+")[:0]")
fmt.Fprintln(g.out, ws+" }")
fmt.Fprintln(g.out, ws+" for !in.IsDelim(']') {")
fmt.Fprintln(g.out, ws+" var "+tmpVar+" "+g.getType(elem))