You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.8 KiB

  1. {{var "v"}} := {{if not isArray}}*{{end}}{{ .Varname }}
  2. {{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() {{/* // helper, containerLenS */}}{{if not isArray}}
  3. var {{var "c"}} bool {{/* // changed */}}
  4. _ = {{var "c"}}{{end}}
  5. if {{var "l"}} == 0 {
  6. {{if isSlice }}if {{var "v"}} == nil {
  7. {{var "v"}} = []{{ .Typ }}{}
  8. {{var "c"}} = true
  9. } else if len({{var "v"}}) != 0 {
  10. {{var "v"}} = {{var "v"}}[:0]
  11. {{var "c"}} = true
  12. } {{end}} {{if isChan }}if {{var "v"}} == nil {
  13. {{var "v"}} = make({{ .CTyp }}, 0)
  14. {{var "c"}} = true
  15. } {{end}}
  16. } else if {{var "l"}} > 0 {
  17. {{if isChan }}if {{var "v"}} == nil {
  18. {{var "rl"}}, _ = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
  19. {{var "v"}} = make({{ .CTyp }}, {{var "rl"}})
  20. {{var "c"}} = true
  21. }
  22. for {{var "r"}} := 0; {{var "r"}} < {{var "l"}}; {{var "r"}}++ {
  23. {{var "h"}}.ElemContainerState({{var "r"}})
  24. var {{var "t"}} {{ .Typ }}
  25. {{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }}
  26. {{var "v"}} <- {{var "t"}}
  27. }
  28. {{ else }} var {{var "rr"}}, {{var "rl"}} int {{/* // num2read, length of slice/array/chan */}}
  29. var {{var "rt"}} bool {{/* truncated */}}
  30. _, _ = {{var "rl"}}, {{var "rt"}}
  31. {{var "rr"}} = {{var "l"}} // len({{var "v"}})
  32. if {{var "l"}} > cap({{var "v"}}) {
  33. {{if isArray }}z.DecArrayCannotExpand(len({{var "v"}}), {{var "l"}})
  34. {{ else }}{{if not .Immutable }}
  35. {{var "rg"}} := len({{var "v"}}) > 0
  36. {{var "v2"}} := {{var "v"}} {{end}}
  37. {{var "rl"}}, {{var "rt"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
  38. if {{var "rt"}} {
  39. if {{var "rl"}} <= cap({{var "v"}}) {
  40. {{var "v"}} = {{var "v"}}[:{{var "rl"}}]
  41. } else {
  42. {{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
  43. }
  44. } else {
  45. {{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
  46. }
  47. {{var "c"}} = true
  48. {{var "rr"}} = len({{var "v"}}) {{if not .Immutable }}
  49. if {{var "rg"}} { copy({{var "v"}}, {{var "v2"}}) } {{end}} {{end}}{{/* end not Immutable, isArray */}}
  50. } {{if isSlice }} else if {{var "l"}} != len({{var "v"}}) {
  51. {{var "v"}} = {{var "v"}}[:{{var "l"}}]
  52. {{var "c"}} = true
  53. } {{end}} {{/* end isSlice:47 */}}
  54. {{var "j"}} := 0
  55. for ; {{var "j"}} < {{var "rr"}} ; {{var "j"}}++ {
  56. {{var "h"}}.ElemContainerState({{var "j"}})
  57. {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
  58. }
  59. {{if isArray }}for ; {{var "j"}} < {{var "l"}} ; {{var "j"}}++ {
  60. {{var "h"}}.ElemContainerState({{var "j"}})
  61. z.DecSwallow()
  62. }
  63. {{ else }}if {{var "rt"}} {
  64. for ; {{var "j"}} < {{var "l"}} ; {{var "j"}}++ {
  65. {{var "v"}} = append({{var "v"}}, {{ zero}})
  66. {{var "h"}}.ElemContainerState({{var "j"}})
  67. {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
  68. }
  69. } {{end}} {{/* end isArray:56 */}}
  70. {{end}} {{/* end isChan:16 */}}
  71. } else { {{/* len < 0 */}}
  72. {{var "j"}} := 0
  73. for ; !r.CheckBreak(); {{var "j"}}++ {
  74. {{if isChan }}
  75. {{var "h"}}.ElemContainerState({{var "j"}})
  76. var {{var "t"}} {{ .Typ }}
  77. {{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }}
  78. {{var "v"}} <- {{var "t"}}
  79. {{ else }}
  80. if {{var "j"}} >= len({{var "v"}}) {
  81. {{if isArray }}z.DecArrayCannotExpand(len({{var "v"}}), {{var "j"}}+1)
  82. {{ else }}{{var "v"}} = append({{var "v"}}, {{zero}})// var {{var "z"}} {{ .Typ }}
  83. {{var "c"}} = true {{end}}
  84. }
  85. {{var "h"}}.ElemContainerState({{var "j"}})
  86. if {{var "j"}} < len({{var "v"}}) {
  87. {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
  88. } else {
  89. z.DecSwallow()
  90. }
  91. {{end}}
  92. }
  93. {{if isSlice }}if {{var "j"}} < len({{var "v"}}) {
  94. {{var "v"}} = {{var "v"}}[:{{var "j"}}]
  95. {{var "c"}} = true
  96. } else if {{var "j"}} == 0 && {{var "v"}} == nil {
  97. {{var "v"}} = []{{ .Typ }}{}
  98. {{var "c"}} = true
  99. }{{end}}
  100. }
  101. {{var "h"}}.End()
  102. {{if not isArray }}if {{var "c"}} {
  103. *{{ .Varname }} = {{var "v"}}
  104. }{{end}}