Source file
test/codegen/append_freegc.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
77
78 r = append(r, new(i))
79 }
80
81 return r
82 }
83
84 func Append7(n int) []*int {
85 var r []*int
86 for i := range n {
87
88
89
90 r = append(r, new(i))
91 }
92 println(cap(r))
93
94 return r
95 }
96
97 func Append8(n int, p *[]int) {
98 var r []int
99 for i := range n {
100
101 r = append(r, i)
102 }
103
104 *p = r
105 }
106
107 func Append8b(n int, p *[]int) {
108 var r []int
109
110 *p = r
111 for i := range n {
112
113 r = append(r, i)
114 }
115 }
116
117 func Append9(n int) []int {
118 var r []int
119 for i := range n {
120
121 r = append(r, i)
122 }
123 println(len(r))
124
125 return r
126 }
127
128 func Append10(n int) []int {
129 var r []int
130 for i := range n {
131
132 r = append(r, i)
133 }
134 println(r[3])
135
136 return r
137 }
138
139 func Append11(n int) []int {
140 var r []int
141 for i := range n {
142
143 r = append(r, i)
144 }
145 r = r[3:5]
146
147 return r
148 }
149
150 func Append12(n int) []int {
151 var r []int
152 r = nil
153 for i := range n {
154
155 r = append(r, i)
156 }
157
158 return r
159 }
160
161 func Append13(n int) []int {
162 var r []int
163 r, r = nil, nil
164 for i := range n {
165
166 r = append(r, i)
167 }
168
169 return r
170 }
171
172 func Append14(n int) []int {
173 var r []int
174 r = []int{3, 4, 5}
175 for i := range n {
176
177 r = append(r, i)
178 }
179
180 return r
181 }
182
183 func Append15(n int) []int {
184 r := []int{3, 4, 5}
185 for i := range n {
186
187 r = append(r, i)
188 }
189
190 return r
191 }
192
193 func Append16(r []int, n int) []int {
194 for i := range n {
195
196 r = append(r, i)
197 }
198
199 return r
200 }
201
202 func Append17(n int) []int {
203 var r []int
204 for i := range n {
205
206 r = append(r, i)
207 }
208 for i, x := range r {
209 println(i, x)
210 }
211
212 return r
213 }
214
215
216 func useSlice(s []int) {
217 }
218
View as plain text