gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

gen-dec-array.go.tmpl (2890B)


      1 {{var "v"}} := {{if not isArray}}*{{end}}{{ .Varname }}
      2 {{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() {{/* // helper, containerLenS */}}
      3 {{if not isArray -}}
      4 var {{var "c"}} bool {{/* // changed */}}
      5 _ = {{var "c"}}
      6 if {{var "h"}}.IsNil {
      7 	if {{var "v"}} != nil {
      8 		{{var "v"}} = nil
      9 		{{var "c"}} = true
     10 	}
     11 } else {{end -}}
     12 if {{var "l"}} == 0 {
     13 	{{if isSlice -}}
     14 	if {{var "v"}} == nil {
     15 		{{var "v"}} = []{{ .Typ }}{}
     16 		{{var "c"}} = true
     17 	} else if len({{var "v"}}) != 0 {
     18 		{{var "v"}} = {{var "v"}}[:0]
     19 		{{var "c"}} = true
     20 	} {{else if isChan }}if {{var "v"}} == nil {
     21 		{{var "v"}} = make({{ .CTyp }}, 0)
     22 		{{var "c"}} = true
     23 	}
     24     {{end -}}
     25 } else {
     26 	{{var "hl"}} := {{var "l"}} > 0
     27 	var {{var "rl"}} int
     28 	_ =  {{var "rl"}}
     29 	{{if isSlice }} if {{var "hl"}} {
     30 	if {{var "l"}} > cap({{var "v"}}) {
     31 		{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
     32 		if {{var "rl"}} <= cap({{var "v"}}) {
     33 			{{var "v"}} = {{var "v"}}[:{{var "rl"}}]
     34 		} else {
     35 			{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
     36 		}
     37 		{{var "c"}} = true
     38 	} else if {{var "l"}} != len({{var "v"}}) {
     39 		{{var "v"}} = {{var "v"}}[:{{var "l"}}]
     40 		{{var "c"}} = true
     41 	}
     42 	}
     43     {{end -}}
     44 	var {{var "j"}} int 
     45 	{{/* // var {{var "dn"}} bool */ -}}
     46 	for {{var "j"}} = 0; z.DecContainerNext({{var "j"}}, {{var "l"}}, {{var "hl"}}); {{var "j"}}++ {
     47 		{{if not isArray}} if {{var "j"}} == 0 && {{var "v"}} == nil {
     48 			if {{var "hl"}} {
     49 				{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
     50 			} else {
     51 				{{var "rl"}} = {{if isSlice}}8{{else if isChan}}64{{end}}
     52 			}
     53 			{{var "v"}} = make({{if isSlice}}[]{{ .Typ }}{{else if isChan}}{{.CTyp}}{{end}}, {{var "rl"}})
     54 			{{var "c"}} = true 
     55 		}
     56         {{end -}}
     57 		{{var "h"}}.ElemContainerState({{var "j"}})
     58         {{/* {{var "dn"}} = r.TryDecodeAsNil() */}}{{/* commented out, as decLineVar handles this already each time */ -}}
     59         {{if isChan}}{{ $x := printf "%[1]vvcx%[2]v" .TempVar .Rand }}var {{$x}} {{ .Typ }}
     60 		{{ decLineVar $x -}}
     61 		{{var "v"}} <- {{ $x }}
     62         {{else}}{{/* // if indefinite, etc, then expand the slice if necessary */ -}}
     63 		var {{var "db"}} bool
     64 		if {{var "j"}} >= len({{var "v"}}) {
     65 			{{if isSlice }} {{var "v"}} = append({{var "v"}}, {{ zero }})
     66 			{{var "c"}} = true
     67 			{{else}} z.DecArrayCannotExpand(len(v), {{var "j"}}+1); {{var "db"}} = true
     68 			{{end -}}
     69 		}
     70 		if {{var "db"}} {
     71 			z.DecSwallow()
     72 		} else {
     73 			{{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x -}}
     74 		}
     75         {{end -}}
     76 	}
     77 	{{if isSlice}} if {{var "j"}} < len({{var "v"}}) {
     78 		{{var "v"}} = {{var "v"}}[:{{var "j"}}]
     79 		{{var "c"}} = true
     80 	} else if {{var "j"}} == 0 && {{var "v"}} == nil {
     81 		{{var "v"}} = []{{ .Typ }}{}
     82 		{{var "c"}} = true
     83 	}
     84     {{end -}}
     85 }
     86 {{var "h"}}.End()
     87 {{if not isArray }}if {{var "c"}} { 
     88 	*{{ .Varname }} = {{var "v"}}
     89 }
     90 {{end -}}