Source file
test/codegen/append.go
1
2
3
4
5
6
7
8
9 package codegen
10
11 func Append1(n int) []int {
12 var r []int
13 for i := range n {
14
15 r = append(r, i)
16 }
17
18 return r
19 }
20
21 func Append2(n int) (r []int) {
22 for i := range n {
23
24 r = append(r, i)
25 }
26
27 return
28 }
29
30 func Append3(n int) (r []int) {
31 for i := range n {
32
33 r = append(r, i)
34 }
35
36 return r
37 }
38
39 func Append4(n int) []int {
40 var r []int
41 for i := range n {
42
43 r = append(r, i)
44 }
45 println(cap(r))
46
47 return r
48 }
49
50 func Append5(n int) []int {
51 var r []int
52 for i := range n {
53
54 r = append(r, i)
55 }
56 useSlice(r)
57
58 return r
59 }
60
61 func Append5b(n int) []int {
62 var r []int
63 useSlice(r)
64 for i := range n {
65
66 r = append(r, i)
67 }
68
69 return r
70 }
71
72 func Append6(n int) []*int {
73 var r []*int
74 for i := range n {
75
76 r = append(r, new(i))
77 }
78
79 return r
80 }
81
82 func Append7(n int) []*int {
83 var r []*int
84 for i := range n {
85
86 r = append(r, new(i))
87 }
88 println(cap(r))
89
90 return r
91 }
92
93 func Append8(n int, p *[]int) {
94 var r []int
95 for i := range n {
96
97 r = append(r, i)
98 }
99
100 *p = r
101 }
102
103 func Append8b(n int, p *[]int) {
104 var r []int
105
106 *p = r
107 for i := range n {
108
109 r = append(r, i)
110 }
111 }
112
113 func Append9(n int) []int {
114 var r []int
115 for i := range n {
116
117 r = append(r, i)
118 }
119 println(len(r))
120
121 return r
122 }
123
124 func Append10(n int) []int {
125 var r []int
126 for i := range n {
127
128 r = append(r, i)
129 }
130 println(r[3])
131
132 return r
133 }
134
135 func Append11(n int) []int {
136 var r []int
137 for i := range n {
138
139 r = append(r, i)
140 }
141 r = r[3:5]
142
143 return r
144 }
145
146 func Append12(n int) []int {
147 var r []int
148 r = nil
149 for i := range n {
150
151 r = append(r, i)
152 }
153
154 return r
155 }
156
157 func Append13(n int) []int {
158 var r []int
159 r, r = nil, nil
160 for i := range n {
161
162 r = append(r, i)
163 }
164
165 return r
166 }
167
168 func Append14(n int) []int {
169 var r []int
170 r = []int{3, 4, 5}
171 for i := range n {
172
173 r = append(r, i)
174 }
175
176 return r
177 }
178
179 func Append15(n int) []int {
180 r := []int{3, 4, 5}
181 for i := range n {
182
183 r = append(r, i)
184 }
185
186 return r
187 }
188
189 func Append16(r []int, n int) []int {
190 for i := range n {
191
192 r = append(r, i)
193 }
194
195 return r
196 }
197
198 func Append17(n int) []int {
199 var r []int
200 for i := range n {
201
202 r = append(r, i)
203 }
204 for i, x := range r {
205 println(i, x)
206 }
207
208 return r
209 }
210
211 func Append18(n int, p *[]int) {
212 var r []int
213 for i := range n {
214
215 *p = r
216
217 r = append(r, i)
218 }
219 }
220
221 func Append19(n int, p [][]int) {
222 for j := range p {
223 var r []int
224 for i := range n {
225
226 r = append(r, i)
227 }
228
229 p[j] = r
230 }
231 }
232
233 func Append20(n int, p [][]int) {
234 for j := range p {
235 var r []int
236
237 r = append(r, 0)
238
239 p[j] = r
240 }
241 }
242
243
244 func useSlice(s []int) {
245 }
246
View as plain text