mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
71 lines
2.2 KiB
Cheetah
71 lines
2.2 KiB
Cheetah
|
{{var "v"}} := {{if not isArray}}*{{end}}{{ .Varname }}
|
||
|
{{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() {{/* // helper, containerLenS */}}{{if not isArray}}
|
||
|
var {{var "c"}} bool {{/* // changed */}}
|
||
|
_ = {{var "c"}}{{end}}
|
||
|
if {{var "l"}} == 0 {
|
||
|
{{if isSlice }}if {{var "v"}} == nil {
|
||
|
{{var "v"}} = []{{ .Typ }}{}
|
||
|
{{var "c"}} = true
|
||
|
} else if len({{var "v"}}) != 0 {
|
||
|
{{var "v"}} = {{var "v"}}[:0]
|
||
|
{{var "c"}} = true
|
||
|
} {{end}} {{if isChan }}if {{var "v"}} == nil {
|
||
|
{{var "v"}} = make({{ .CTyp }}, 0)
|
||
|
{{var "c"}} = true
|
||
|
} {{end}}
|
||
|
} else {
|
||
|
{{var "hl"}} := {{var "l"}} > 0
|
||
|
var {{var "rl"}} int
|
||
|
{{if isSlice }} if {{var "hl"}} {
|
||
|
if {{var "l"}} > cap({{var "v"}}) {
|
||
|
{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
|
||
|
if {{var "rl"}} <= cap({{var "v"}}) {
|
||
|
{{var "v"}} = {{var "v"}}[:{{var "rl"}}]
|
||
|
} else {
|
||
|
{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
|
||
|
}
|
||
|
{{var "c"}} = true
|
||
|
} else if {{var "l"}} != len({{var "v"}}) {
|
||
|
{{var "v"}} = {{var "v"}}[:{{var "l"}}]
|
||
|
{{var "c"}} = true
|
||
|
}
|
||
|
} {{end}}
|
||
|
{{var "j"}} := 0
|
||
|
for ; ({{var "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || r.CheckBreak()); {{var "j"}}++ {
|
||
|
if {{var "j"}} == 0 && len({{var "v"}}) == 0 {
|
||
|
if {{var "hl"}} {
|
||
|
{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
|
||
|
} else {
|
||
|
{{var "rl"}} = 8
|
||
|
}
|
||
|
{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
|
||
|
{{var "c"}} = true
|
||
|
}
|
||
|
// if indefinite, etc, then expand the slice if necessary
|
||
|
var {{var "db"}} bool
|
||
|
if {{var "j"}} >= len({{var "v"}}) {
|
||
|
{{if isSlice }} {{var "v"}} = append({{var "v"}}, {{ zero }}); {{var "c"}} = true
|
||
|
{{end}} {{if isArray}} z.DecArrayCannotExpand(len(v), {{var "j"}}+1); {{var "db"}} = true
|
||
|
{{end}}
|
||
|
}
|
||
|
{{var "h"}}.ElemContainerState({{var "j"}})
|
||
|
if {{var "db"}} {
|
||
|
z.DecSwallow()
|
||
|
} else {
|
||
|
{{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
|
||
|
}
|
||
|
}
|
||
|
{{if isSlice}} if {{var "j"}} < len({{var "v"}}) {
|
||
|
{{var "v"}} = {{var "v"}}[:{{var "j"}}]
|
||
|
{{var "c"}} = true
|
||
|
} else if {{var "j"}} == 0 && {{var "v"}} == nil {
|
||
|
{{var "v"}} = make([]{{ .Typ }}, 0)
|
||
|
{{var "c"}} = true
|
||
|
} {{end}}
|
||
|
}
|
||
|
{{var "h"}}.End()
|
||
|
{{if not isArray }}if {{var "c"}} {
|
||
|
*{{ .Varname }} = {{var "v"}}
|
||
|
}{{end}}
|
||
|
|