mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
marshal and unmarshal in place in arrays
that avoids a copy of each item.
This commit is contained in:
+1
-4
@@ -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+" }")
|
||||
|
||||
+2
-3
@@ -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(']')")
|
||||
|
||||
Reference in New Issue
Block a user