Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime | 5 package runtime |
6 #include "runtime.h" | 6 #include "runtime.h" |
7 #include "arch_GOARCH.h" | 7 #include "arch_GOARCH.h" |
8 #include "type.h" | 8 #include "type.h" |
9 #include "typekind.h" | 9 #include "typekind.h" |
10 #include "malloc.h" | 10 #include "malloc.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 } while(newcap1 < newcap); | 115 } while(newcap1 < newcap); |
116 } | 116 } |
117 | 117 |
118 if(newcap1 > MaxMem/typ->size) | 118 if(newcap1 > MaxMem/typ->size) |
119 runtime·panicstring("growslice: cap out of range"); | 119 runtime·panicstring("growslice: cap out of range"); |
120 capmem = runtime·roundupsize(newcap1*typ->size); | 120 capmem = runtime·roundupsize(newcap1*typ->size); |
121 flag = 0; | 121 flag = 0; |
122 // Can't use FlagNoZero w/o FlagNoScan, because otherwise GC can scan un itialized memory. | 122 // Can't use FlagNoZero w/o FlagNoScan, because otherwise GC can scan un itialized memory. |
123 if(typ->kind&KindNoPointers) | 123 if(typ->kind&KindNoPointers) |
124 flag = FlagNoScan|FlagNoZero; | 124 flag = FlagNoScan|FlagNoZero; |
125 ret->array = runtime·mallocgc(capmem, (uintptr)typ|TypeInfo_Array, flag) ; | |
126 ret->len = x.len; | 125 ret->len = x.len; |
127 ret->cap = capmem/typ->size; | 126 ret->cap = capmem/typ->size; |
127 capmem = ret->cap*typ->size; | |
dfc
2014/07/21 10:26:04
I think this needs a short comment to explain how
dvyukov
2014/07/21 12:14:50
Done.
| |
128 ret->array = runtime·mallocgc(capmem, (uintptr)typ|TypeInfo_Array, flag) ; | |
128 lenmem = x.len*typ->size; | 129 lenmem = x.len*typ->size; |
129 runtime·memmove(ret->array, x.array, lenmem); | 130 runtime·memmove(ret->array, x.array, lenmem); |
130 if(typ->kind&KindNoPointers) | 131 if(typ->kind&KindNoPointers) |
131 runtime·memclr(ret->array+lenmem, capmem-lenmem); | 132 runtime·memclr(ret->array+lenmem, capmem-lenmem); |
132 } | 133 } |
133 | 134 |
134 #pragma textflag NOSPLIT | 135 #pragma textflag NOSPLIT |
135 func copy(to Slice, fm Slice, width uintptr) (ret int) { | 136 func copy(to Slice, fm Slice, width uintptr) (ret int) { |
136 void *pc; | 137 void *pc; |
137 | 138 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 } | 196 } |
196 | 197 |
197 func printslice(a Slice) { | 198 func printslice(a Slice) { |
198 runtime·prints("["); | 199 runtime·prints("["); |
199 runtime·printint(a.len); | 200 runtime·printint(a.len); |
200 runtime·prints("/"); | 201 runtime·prints("/"); |
201 runtime·printint(a.cap); | 202 runtime·printint(a.cap); |
202 runtime·prints("]"); | 203 runtime·prints("]"); |
203 runtime·printpointer(a.array); | 204 runtime·printpointer(a.array); |
204 } | 205 } |
OLD | NEW |