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 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "type.h" | 6 #include "type.h" |
7 #include "malloc.h" | 7 #include "malloc.h" |
8 | 8 |
9 static int32 debug = 0; | 9 static int32 debug = 0; |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 FLUSH(&ret); | 30 FLUSH(&ret); |
31 | 31 |
32 if(debug) { | 32 if(debug) { |
33 printf("makeslice(%S, %d, %d); ret=", | 33 printf("makeslice(%S, %d, %d); ret=", |
34 *t->string, nel, cap); | 34 *t->string, nel, cap); |
35 ·printslice(ret); | 35 ·printslice(ret); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 static void | |
40 throwslice(uint32 lb, uint32 hb, uint32 n) | |
41 { | |
42 prints("slice["); | |
43 ·printint(lb); | |
44 prints(":"); | |
45 ·printint(hb); | |
46 prints("] of ["); | |
47 ·printint(n); | |
48 prints("] array\n"); | |
49 throw("array slice"); | |
50 } | |
51 | |
52 // sliceslice(old []any, lb int, hb int, width int) (ary []any); | 39 // sliceslice(old []any, lb int, hb int, width int) (ary []any); |
53 void | 40 void |
54 ·sliceslice(Slice old, uint32 lb, uint32 hb, uint32 width, Slice ret) | 41 ·sliceslice(Slice old, uint32 lb, uint32 hb, uint32 width, Slice ret) |
55 { | 42 { |
56 if(hb > old.cap || lb > hb) { | 43 if(hb > old.cap || lb > hb) { |
57 if(debug) { | 44 if(debug) { |
58 prints("runtime.sliceslice: old="); | 45 prints("runtime.sliceslice: old="); |
59 ·printslice(old); | 46 ·printslice(old); |
60 prints("; lb="); | 47 prints("; lb="); |
61 ·printint(lb); | 48 ·printint(lb); |
62 prints("; hb="); | 49 prints("; hb="); |
63 ·printint(hb); | 50 ·printint(hb); |
64 prints("; width="); | 51 prints("; width="); |
65 ·printint(width); | 52 ·printint(width); |
66 prints("\n"); | 53 prints("\n"); |
67 | 54 |
68 prints("oldarray: nel="); | 55 prints("oldarray: nel="); |
69 ·printint(old.len); | 56 ·printint(old.len); |
70 prints("; cap="); | 57 prints("; cap="); |
71 ·printint(old.cap); | 58 ·printint(old.cap); |
72 prints("\n"); | 59 prints("\n"); |
73 } | 60 } |
74 » » throwslice(lb, hb, old.cap); | 61 » » ·panicslice(); |
75 } | 62 } |
76 | 63 |
77 // new array is inside old array | 64 // new array is inside old array |
78 ret.len = hb - lb; | 65 ret.len = hb - lb; |
79 ret.cap = old.cap - lb; | 66 ret.cap = old.cap - lb; |
80 ret.array = old.array + lb*width; | 67 ret.array = old.array + lb*width; |
81 | 68 |
82 FLUSH(&ret); | 69 FLUSH(&ret); |
83 | 70 |
84 if(debug) { | 71 if(debug) { |
(...skipping 24 matching lines...) Expand all Loading... |
109 prints("; width="); | 96 prints("; width="); |
110 ·printint(width); | 97 ·printint(width); |
111 prints("\n"); | 98 prints("\n"); |
112 | 99 |
113 prints("oldarray: nel="); | 100 prints("oldarray: nel="); |
114 ·printint(old.len); | 101 ·printint(old.len); |
115 prints("; cap="); | 102 prints("; cap="); |
116 ·printint(old.cap); | 103 ·printint(old.cap); |
117 prints("\n"); | 104 prints("\n"); |
118 } | 105 } |
119 » » throwslice(lb, old.len, old.cap); | 106 » » ·panicslice(); |
120 } | 107 } |
121 | 108 |
122 // new array is inside old array | 109 // new array is inside old array |
123 ret.len = old.len - lb; | 110 ret.len = old.len - lb; |
124 ret.cap = old.cap - lb; | 111 ret.cap = old.cap - lb; |
125 ret.array = old.array + lb*width; | 112 ret.array = old.array + lb*width; |
126 | 113 |
127 FLUSH(&ret); | 114 FLUSH(&ret); |
128 | 115 |
129 if(debug) { | 116 if(debug) { |
(...skipping 28 matching lines...) Expand all Loading... |
158 prints("; nel="); | 145 prints("; nel="); |
159 ·printint(nel); | 146 ·printint(nel); |
160 prints("; lb="); | 147 prints("; lb="); |
161 ·printint(lb); | 148 ·printint(lb); |
162 prints("; hb="); | 149 prints("; hb="); |
163 ·printint(hb); | 150 ·printint(hb); |
164 prints("; width="); | 151 prints("; width="); |
165 ·printint(width); | 152 ·printint(width); |
166 prints("\n"); | 153 prints("\n"); |
167 } | 154 } |
168 » » throwslice(lb, hb, nel); | 155 » » ·panicslice(); |
169 } | 156 } |
170 | 157 |
171 // new array is inside old array | 158 // new array is inside old array |
172 ret.len = hb-lb; | 159 ret.len = hb-lb; |
173 ret.cap = nel-lb; | 160 ret.cap = nel-lb; |
174 ret.array = old + lb*width; | 161 ret.array = old + lb*width; |
175 | 162 |
176 FLUSH(&ret); | 163 FLUSH(&ret); |
177 | 164 |
178 if(debug) { | 165 if(debug) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 void | 219 void |
233 ·printslice(Slice a) | 220 ·printslice(Slice a) |
234 { | 221 { |
235 prints("["); | 222 prints("["); |
236 ·printint(a.len); | 223 ·printint(a.len); |
237 prints("/"); | 224 prints("/"); |
238 ·printint(a.cap); | 225 ·printint(a.cap); |
239 prints("]"); | 226 prints("]"); |
240 ·printpointer(a.array); | 227 ·printpointer(a.array); |
241 } | 228 } |
OLD | NEW |