diff --git a/gen/decoder.go b/gen/decoder.go index 424195d..21fea2f 100644 --- a/gen/decoder.go +++ b/gen/decoder.go @@ -124,7 +124,6 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field } case reflect.Array: - tmpVar := g.uniqueVarName() iterVar := g.uniqueVarName() elem := t.Elem() @@ -145,11 +144,9 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field fmt.Fprintln(g.out, ws+" in.Delim('[')") fmt.Fprintln(g.out, ws+" "+iterVar+" := 0") fmt.Fprintln(g.out, ws+" for !in.IsDelim(']') && "+iterVar+" < "+fmt.Sprint(length)+" {") - fmt.Fprintln(g.out, ws+" var "+tmpVar+" "+g.getType(elem)) - g.genTypeDecoder(elem, tmpVar, tags, indent+2) + g.genTypeDecoder(elem, out+"["+iterVar+"]", tags, indent+2) - fmt.Fprintln(g.out, ws+" "+out+"["+iterVar+"] = "+tmpVar) fmt.Fprintln(g.out, ws+" "+iterVar+"++") fmt.Fprintln(g.out, ws+" in.WantComma()") fmt.Fprintln(g.out, ws+" }") diff --git a/gen/encoder.go b/gen/encoder.go index 4765317..8775b0c 100644 --- a/gen/encoder.go +++ b/gen/encoder.go @@ -140,18 +140,17 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT case reflect.Array: elem := t.Elem() iVar := g.uniqueVarName() - vVar := g.uniqueVarName() if t.Elem().Kind() == reflect.Uint8 { fmt.Fprintln(g.out, ws+"out.Base64Bytes("+in+"[:])") } else { fmt.Fprintln(g.out, ws+"out.RawByte('[')") - fmt.Fprintln(g.out, ws+"for "+iVar+", "+vVar+" := range "+in+" {") + fmt.Fprintln(g.out, ws+"for "+iVar+" := range "+in+" {") fmt.Fprintln(g.out, ws+" if "+iVar+" > 0 {") fmt.Fprintln(g.out, ws+" out.RawByte(',')") fmt.Fprintln(g.out, ws+" }") - g.genTypeEncoder(elem, vVar, tags, indent+1) + g.genTypeEncoder(elem, in+"["+iVar+"]", tags, indent+1) fmt.Fprintln(g.out, ws+"}") fmt.Fprintln(g.out, ws+"out.RawByte(']')")