author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 18 Apr 2013 20:41:50 +0200 | |
branch | jv |
changeset 18045 | c0c600e0d3b3 |
parent 18043 | 03660093fe98 |
parent 15061 | fea9df1c613a |
child 18084 | ab5b38bd8f81 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
155 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5347
21b418ac4cc3
oops: from:to:do: failed badly when stopIndex was < startIndex.
Claus Gittinger <cg@exept.de>
parents:
5049
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
21b418ac4cc3
oops: from:to:do: failed badly when stopIndex was < startIndex.
Claus Gittinger <cg@exept.de>
parents:
5049
diff
changeset
|
13 |
|
1 | 14 |
ArrayedCollection variableSubclass:#Array |
1083
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
15 |
instanceVariableNames:'' |
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
16 |
classVariableNames:'' |
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
17 |
poolDictionaries:'' |
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
18 |
category:'Collections-Arrayed' |
1 | 19 |
! |
20 |
||
1903 | 21 |
!Array class methodsFor:'documentation'! |
77 | 22 |
|
554 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
77 | 37 |
documentation |
38 |
" |
|
14632 | 39 |
Instances of Array store general objects; the arrays size is fixed, |
40 |
therefore add:/remove: are not allowed. |
|
41 |
(actually, #add: is implemented for compatibility with smalltalks which |
|
1266 | 42 |
provide it, but it is very slow and outputs an annoying warning message ...) |
43 |
||
44 |
Access to the individual elements is via an integer index, |
|
45 |
using the well-known access messages #at: and #at:put:. |
|
399 | 46 |
|
1903 | 47 |
Since Arrays are used very often in the system (either directly or a data-container |
14632 | 48 |
of more complex collection classes), some methods have been tuned by reimplementing |
49 |
them as primitives. Also, the compiler inline-codes some operations |
|
1903 | 50 |
(especially: the above accessing messages). |
92 | 51 |
|
14632 | 52 |
Notice that Array is a built-in class |
53 |
(i.e. the VM knows about its representation). |
|
54 |
Therefore it is NOT possible to add named instance variables or change |
|
55 |
Arrays inheritance. |
|
56 |
However, subclassing is allowed of course |
|
1266 | 57 |
- even with added named instance variables. |
92 | 58 |
|
59 |
Literal arrays (i.e. array-constants) are entered in source as: |
|
1266 | 60 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
61 |
#( element1 element2 ... element-n) |
1266 | 62 |
|
63 |
where each element must be itself a literal constant. |
|
64 |
Array, symbol and byteArray constants within an array can be written |
|
65 |
without the initial #-character. |
|
66 |
In addition, true, false and nil are also allowed as array-literal. |
|
399 | 67 |
|
92 | 68 |
Examples: |
1266 | 69 |
#(1 2 3) -> 3 elements: 1, 2 and 3 |
70 |
#('foo' 2 (1 2)) -> 3 elements: a String, 2 and anotherArray |
|
71 |
#('foo' #(1 2) #foo) -> 3 elements: a String, another array and a symbol |
|
72 |
#('foo' (1 2) foo) -> same as above |
|
73 |
#(nil true #true) -> 3 elements: nil, true and a symbol (watch out) |
|
74 |
#(two [3 3 3] (4 4 4)) -> 3 elements: a symbol, a byteArray and another array |
|
1276 | 75 |
|
4062 | 76 |
[memory requirements:] |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
77 |
OBJ-HEADER + (size * ptr-size) |
4062 | 78 |
|
2145 | 79 |
[warning:] |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
80 |
read the warning about 'growing fixed size collection' |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
81 |
in ArrayedCollection's documentation |
1276 | 82 |
|
1290 | 83 |
[author:] |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
84 |
Claus Gittinger |
1290 | 85 |
|
1276 | 86 |
[see also:] |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
87 |
OrderedCollection |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
88 |
ByteArray FloatArray DoubleArray |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
89 |
String |
77 | 90 |
" |
626 | 91 |
! ! |
3 | 92 |
|
1903 | 93 |
!Array class methodsFor:'instance creation'! |
249 | 94 |
|
95 |
basicNew:anInteger |
|
96 |
"return an instance of myself with anInteger indexed variables. |
|
97 |
Since Array-creation is so common (all other collections use them), |
|
98 |
it seems worth to have a specially tuned version here." |
|
99 |
||
100 |
%{ /* NOCONTEXT */ |
|
101 |
||
102 |
OBJ newobj; |
|
14687 | 103 |
unsigned INT nInstVars; |
104 |
unsigned INT instsize; |
|
249 | 105 |
INT nindexedinstvars; |
106 |
REGISTER OBJ *op; |
|
107 |
||
108 |
if (__isSmallInteger(anInteger)) { |
|
1133 | 109 |
nindexedinstvars = __intVal(anInteger); |
249 | 110 |
if (nindexedinstvars >= 0) { |
1133 | 111 |
nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars); |
249 | 112 |
|
113 |
nInstVars += nindexedinstvars; |
|
114 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
2915 | 115 |
if (__CanDoQuickAlignedNew(instsize)) { /* OBJECT ALLOCATION */ |
357 | 116 |
/* |
117 |
* the most common case |
|
118 |
*/ |
|
835 | 119 |
__qCheckedAlignedNew(newobj, instsize); |
357 | 120 |
ok: ; |
1133 | 121 |
__InstPtr(newobj)->o_class = self; |
369 | 122 |
__qSTORE(newobj, self); |
123 |
||
14623 | 124 |
#if (POINTER_SIZE == 4) && defined(memset4) && defined(FAST_ARRAY_MEMSET4) |
1133 | 125 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
249 | 126 |
#else |
127 |
# if !defined(NEGATIVE_ADDRESSES) |
|
128 |
/* |
|
129 |
* knowing that nil is 0 |
|
130 |
*/ |
|
14657 | 131 |
# ifdef __sparc__ |
132 |
# define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
|
133 |
# endif |
|
2979 | 134 |
|
14657 | 135 |
# ifdef __VMS__ |
136 |
# define FAST_ARRAY_MEMSET_LONGLONG_UNROLLED |
|
137 |
# endif |
|
2979 | 138 |
|
249 | 139 |
# if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED) |
1133 | 140 |
op = __InstPtr(newobj)->i_instvars; |
249 | 141 |
if (nInstVars > 8) { |
142 |
*op++ = nil; /* for alignment */ |
|
143 |
nInstVars--; |
|
144 |
while (nInstVars >= 8) { |
|
145 |
*(double *)op = 0.0; |
|
146 |
((double *)op)[1] = 0.0; |
|
147 |
((double *)op)[2] = 0.0; |
|
148 |
((double *)op)[3] = 0.0; |
|
149 |
op += 8; |
|
150 |
nInstVars -= 8; |
|
151 |
} |
|
152 |
} |
|
153 |
while (nInstVars) { |
|
154 |
*op++ = 0; |
|
155 |
nInstVars--; |
|
156 |
} |
|
157 |
# else |
|
14623 | 158 |
# if (POINTER_SIZE == 4) && defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED) |
2979 | 159 |
# ifdef INT64 |
160 |
# define LONGLONG INT64 |
|
161 |
# else |
|
162 |
# define LONGLONG long long |
|
14687 | 163 |
# endif |
2979 | 164 |
|
1133 | 165 |
op = __InstPtr(newobj)->i_instvars; |
249 | 166 |
if (nInstVars > 8) { |
167 |
*op++ = nil; /* for alignment */ |
|
168 |
nInstVars--; |
|
169 |
while (nInstVars >= 8) { |
|
2979 | 170 |
*(LONGLONG *)op = 0; |
171 |
((LONGLONG *)op)[1] = 0; |
|
172 |
((LONGLONG *)op)[2] = 0; |
|
173 |
((LONGLONG *)op)[3] = 0; |
|
249 | 174 |
op += 8; |
175 |
nInstVars -= 8; |
|
176 |
} |
|
177 |
} |
|
178 |
while (nInstVars) { |
|
179 |
*op++ = 0; |
|
180 |
nInstVars--; |
|
181 |
} |
|
182 |
# else |
|
183 |
# if defined(FAST_ARRAY_MEMSET) |
|
1133 | 184 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
249 | 185 |
# else |
1133 | 186 |
op = __InstPtr(newobj)->i_instvars; |
14623 | 187 |
# if (POINTER_SIZE == 4) && defined(INT64) |
2950 | 188 |
while (nInstVars > 1) { |
189 |
*((INT64 *)op) = 0; |
|
190 |
nInstVars -= 2; |
|
191 |
op += 2; |
|
192 |
} |
|
193 |
# endif |
|
14687 | 194 |
while (nInstVars >= 8) { |
195 |
nInstVars -= 8; |
|
196 |
op[0] = nil; op[1] = nil; |
|
197 |
op[2] = nil; op[3] = nil; |
|
198 |
op[4] = nil; op[5] = nil; |
|
199 |
op[6] = nil; op[7] = nil; |
|
200 |
op += 8; |
|
201 |
} |
|
249 | 202 |
while (nInstVars--) |
203 |
*op++ = nil; |
|
204 |
# endif |
|
205 |
# endif |
|
206 |
# endif |
|
207 |
# else |
|
1133 | 208 |
op = __InstPtr(newobj)->i_instvars; |
249 | 209 |
while (nInstVars--) |
210 |
*op++ = nil; |
|
211 |
# endif |
|
212 |
#endif |
|
213 |
RETURN ( newobj ); |
|
357 | 214 |
} else { |
215 |
/* |
|
216 |
* a GC will happen ... |
|
217 |
* have to protect all context stuff |
|
218 |
* (especially for self, but also for backtrace in case of |
|
219 |
* allocation failure) |
|
220 |
*/ |
|
834 | 221 |
__PROTECT_CONTEXT__ |
14687 | 222 |
newobj = __STX___new((INT)instsize); |
834 | 223 |
__UNPROTECT_CONTEXT__ |
357 | 224 |
if (newobj != nil) { |
225 |
goto ok; |
|
226 |
} |
|
249 | 227 |
} |
228 |
} |
|
229 |
} |
|
230 |
%}. |
|
231 |
" |
|
232 |
arrive here if something went wrong ... |
|
233 |
figure out what it was |
|
234 |
" |
|
235 |
(anInteger isMemberOf:SmallInteger) ifFalse:[ |
|
236 |
" |
|
237 |
the argument is either not an integer, |
|
238 |
or a LargeInteger (which means that its definitely too big) |
|
239 |
" |
|
240 |
self error:'argument to new: must be Integer'. |
|
241 |
^ nil |
|
242 |
]. |
|
243 |
(anInteger < 0) ifTrue:[ |
|
244 |
" |
|
245 |
the argument is negative, |
|
246 |
" |
|
247 |
self error:'bad (negative) argument to new:'. |
|
248 |
^ nil |
|
249 |
]. |
|
250 |
" |
|
251 |
memory allocation failed. |
|
252 |
When we arrive here, there was no memory, even after |
|
14632 | 253 |
a garbage collect. |
254 |
This means, that the VM wanted to get some more memory from the |
|
249 | 255 |
Operatingsystem, which was not kind enough to give it. |
256 |
Bad luck - you should increase the swap space on your machine. |
|
257 |
" |
|
258 |
^ ObjectMemory allocationFailureSignal raise. |
|
549 | 259 |
! |
260 |
||
261 |
new:anInteger |
|
262 |
"return an instance of myself with anInteger indexed variables. |
|
1266 | 263 |
Redefined here to save a few cycles when executed. |
264 |
(Since this is often called, its worth giving it an extra ilc-slot. |
|
265 |
Future versions of stc will do this automatically.)" |
|
549 | 266 |
|
267 |
^ self basicNew:anInteger |
|
1266 | 268 |
|
269 |
"Modified: 23.4.1996 / 15:52:15 / cg" |
|
360 | 270 |
! ! |
271 |
||
1903 | 272 |
!Array class methodsFor:'queries'! |
345 | 273 |
|
543 | 274 |
isBuiltInClass |
1266 | 275 |
"return true if this class is known by the run-time-system. |
276 |
Here, true is returned for myself, false for subclasses." |
|
345 | 277 |
|
543 | 278 |
^ self == Array |
1243 | 279 |
|
1266 | 280 |
"Modified: 23.4.1996 / 15:55:06 / cg" |
249 | 281 |
! ! |
282 |
||
15061 | 283 |
|
1 | 284 |
!Array methodsFor:'accessing'! |
285 |
||
554 | 286 |
at:index |
287 |
"return the indexed instance variable with index, anInteger. |
|
288 |
Reimplemented here to avoid the additional at:->basicAt: send |
|
14632 | 289 |
(which we can do here, since when arriving here, #at: is obviously not |
1730 | 290 |
redefined in a subclass). |
577 | 291 |
This method is the same as basicAt:." |
543 | 292 |
|
293 |
%{ /* NOCONTEXT */ |
|
294 |
||
14687 | 295 |
REGISTER INT indx; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
296 |
REGISTER OBJ slf; |
14687 | 297 |
REGISTER unsigned INT nIndex; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
298 |
REGISTER OBJ cls; |
554 | 299 |
|
300 |
if (__isSmallInteger(index)) { |
|
4474 | 301 |
indx = __intVal(index) - 1; |
302 |
slf = self; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
303 |
|
4474 | 304 |
nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE); |
305 |
if ((cls = __qClass(slf)) != Array) { |
|
306 |
if (indx < 0) goto badIndex; |
|
307 |
indx += __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
308 |
} |
|
14687 | 309 |
if ((unsigned INT)indx < (unsigned INT)nIndex) { |
4474 | 310 |
RETURN ( __InstPtr(slf)->i_instvars[indx] ); |
311 |
} |
|
554 | 312 |
} |
4385
dbe7d1e8c54c
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4309
diff
changeset
|
313 |
badIndex: ; |
554 | 314 |
%}. |
4474 | 315 |
"/ ^ super at:index |
316 |
^ super basicAt:index "/ knowing that super-#at: does #basicAt: |
|
543 | 317 |
! |
318 |
||
554 | 319 |
at:index put:anObject |
320 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
1219 | 321 |
Returns anObject (sigh). |
554 | 322 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
1730 | 323 |
(which we can do here, since when arriving here, #atput:: is obviously not |
324 |
redefined in a subclass). |
|
577 | 325 |
This method is the same as basicAt:put:." |
549 | 326 |
|
327 |
%{ /* NOCONTEXT */ |
|
328 |
||
14687 | 329 |
REGISTER INT indx; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
330 |
REGISTER OBJ slf; |
14687 | 331 |
REGISTER unsigned INT nIndex; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
332 |
REGISTER OBJ cls; |
554 | 333 |
|
334 |
if (__isSmallInteger(index)) { |
|
4474 | 335 |
indx = __intVal(index) - 1; |
336 |
slf = self; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
337 |
|
4474 | 338 |
nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE); |
339 |
if ((cls = __qClass(slf)) != Array) { |
|
340 |
if (indx < 0) goto badIndex; |
|
341 |
indx += __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
342 |
} |
|
14687 | 343 |
if ((unsigned INT)indx < (unsigned INT)nIndex) { |
4474 | 344 |
__InstPtr(slf)->i_instvars[indx] = anObject; |
345 |
__STORE(slf, anObject); |
|
346 |
RETURN ( anObject ); |
|
347 |
} |
|
554 | 348 |
} |
4385
dbe7d1e8c54c
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4309
diff
changeset
|
349 |
badIndex: ; |
554 | 350 |
%}. |
4474 | 351 |
"/ ^ super at:index put:anObject |
352 |
^ super basicAt:index put:anObject "/ knowing that super-#at:put: does #basicAt:put: |
|
1219 | 353 |
|
354 |
"Modified: 19.4.1996 / 11:16:42 / cg" |
|
549 | 355 |
! |
356 |
||
357 |
basicAt:index |
|
358 |
"return the indexed instance variable with index, anInteger |
|
359 |
- added here for speed" |
|
360 |
||
361 |
%{ /* NOCONTEXT */ |
|
362 |
||
14687 | 363 |
REGISTER INT indx; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
364 |
REGISTER OBJ slf; |
14687 | 365 |
REGISTER unsigned INT nIndex; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
366 |
REGISTER OBJ cls; |
549 | 367 |
|
368 |
if (__isSmallInteger(index)) { |
|
4474 | 369 |
indx = __intVal(index) - 1; |
370 |
slf = self; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
371 |
|
4474 | 372 |
nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE); |
373 |
if ((cls = __qClass(slf)) != Array) { |
|
374 |
if (indx < 0) goto badIndex; |
|
375 |
indx += __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
376 |
} |
|
14687 | 377 |
if ((unsigned INT)indx < (unsigned INT)nIndex) { |
4474 | 378 |
RETURN ( __InstPtr(slf)->i_instvars[indx] ); |
379 |
} |
|
549 | 380 |
} |
4385
dbe7d1e8c54c
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4309
diff
changeset
|
381 |
badIndex: ; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
382 |
%}. |
549 | 383 |
^ super basicAt:index |
384 |
! |
|
385 |
||
77 | 386 |
basicAt:index put:anObject |
1 | 387 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
1219 | 388 |
Returns anObject (sigh). |
1 | 389 |
- added here for speed" |
390 |
||
391 |
%{ /* NOCONTEXT */ |
|
392 |
||
14687 | 393 |
REGISTER INT indx; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
394 |
REGISTER OBJ slf; |
14687 | 395 |
REGISTER unsigned INT nIndex; |
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
396 |
REGISTER OBJ cls; |
1 | 397 |
|
249 | 398 |
if (__isSmallInteger(index)) { |
4474 | 399 |
indx = __intVal(index) - 1; |
400 |
slf = self; |
|
1143
27325100bdf4
can check index against low..hi with a single compare&branch
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
401 |
|
4474 | 402 |
nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE); |
403 |
if ((cls = __qClass(slf)) != Array) { |
|
404 |
if (indx < 0) goto badIndex; |
|
405 |
indx += __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
406 |
} |
|
14687 | 407 |
if ((unsigned INT)indx < (unsigned INT)nIndex) { |
4474 | 408 |
__InstPtr(slf)->i_instvars[indx] = anObject; |
409 |
__STORE(slf, anObject); |
|
410 |
RETURN ( anObject ); |
|
411 |
} |
|
1 | 412 |
} |
4385
dbe7d1e8c54c
oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents:
4309
diff
changeset
|
413 |
badIndex: ; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
414 |
%}. |
77 | 415 |
^ super basicAt:index put:anObject |
1219 | 416 |
|
417 |
"Modified: 19.4.1996 / 11:14:26 / cg" |
|
1 | 418 |
! ! |
419 |
||
11 | 420 |
!Array methodsFor:'converting'! |
421 |
||
422 |
asArray |
|
15061 | 423 |
"return the receiver as an array - that's the receiver itself. |
424 |
Notice: Use asNewArray, if you intent to modify the returned collection." |
|
11 | 425 |
|
426 |
"could be an instance of a subclass..." |
|
427 |
self class == Array ifTrue:[ |
|
15061 | 428 |
^ self |
11 | 429 |
]. |
430 |
^ super asArray |
|
1243 | 431 |
|
432 |
"Modified: 22.4.1996 / 12:42:09 / cg" |
|
12452 | 433 |
! |
434 |
||
435 |
asImmutableArray |
|
436 |
"return a write-protected copy of myself" |
|
437 |
||
14158 | 438 |
"/ self assert:(ImmutableArray notNil). |
439 |
^ self copy beImmutable |
|
440 |
||
441 |
"Modified: / 07-06-2012 / 11:06:48 / cg" |
|
442 |
! |
|
443 |
||
14995 | 444 |
asNewArray |
445 |
"return the receiver as an unique new array." |
|
446 |
||
447 |
"could be an instance of a subclass..." |
|
448 |
self class == Array ifTrue:[ |
|
449 |
^ self copy |
|
450 |
]. |
|
451 |
^ super asArray |
|
452 |
! |
|
453 |
||
14158 | 454 |
beImmutable |
455 |
"make myself write-protected" |
|
456 |
||
457 |
"/ self assert:(ImmutableArray notNil). |
|
458 |
self changeClassTo:ImmutableArray |
|
459 |
||
460 |
"Created: / 07-06-2012 / 11:06:33 / cg" |
|
11 | 461 |
! ! |
462 |
||
1 | 463 |
!Array methodsFor:'copying'! |
464 |
||
465 |
copyWith:something |
|
220 | 466 |
"return a new collection containing the receivers elements |
14632 | 467 |
and the single new element, newElement. |
220 | 468 |
This is different from concatentation, which expects another collection |
469 |
as argument, but equivalent to copy-and-addLast. |
|
370 | 470 |
Reimplemented for speed if receiver is an Array. |
471 |
(since the inherited copyWith uses replaceFromTo:, which is also |
|
472 |
tuned, it is questionable, if we need this)" |
|
473 |
||
474 |
%{ /* NOCONTEXT */ |
|
4122 | 475 |
OBJ nObj; |
14687 | 476 |
unsigned INT sz; |
477 |
unsigned INT nIndex; |
|
11 | 478 |
REGISTER OBJ *srcP, *dstP; |
293 | 479 |
REGISTER int spc; |
1 | 480 |
|
328 | 481 |
if (__qClass(self) == Array) { |
14632 | 482 |
sz = __qSize(self) + sizeof(OBJ); |
483 |
__PROTECT2__(something, self); |
|
484 |
__qAlignedNew(nObj, sz); /* OBJECT ALLOCATION */ |
|
485 |
__UNPROTECT2__(self, something); |
|
92 | 486 |
|
14632 | 487 |
if (nObj) { |
488 |
__InstPtr(nObj)->o_class = Array; |
|
489 |
__qSTORE(nObj, Array); |
|
1 | 490 |
|
14632 | 491 |
nIndex = __BYTES2OBJS__(sz - OHDR_SIZE - sizeof(OBJ)); |
492 |
/* |
|
493 |
* sorry: |
|
494 |
* cannot use bcopy, since we must take care of stores ... |
|
495 |
* could check for: notRemembered + inOld + notLifoRem |
|
496 |
* + not incrGCRunning |
|
497 |
* but: copyWith is not heavily used by real programmers ... |
|
498 |
*/ |
|
499 |
spc = __qSpace(nObj); |
|
500 |
srcP = __arrayVal(self); |
|
501 |
dstP = __arrayVal(nObj); |
|
1903 | 502 |
|
8919 | 503 |
#ifdef __UNROLL_LOOPS__ |
14632 | 504 |
while (nIndex >= 4) { |
505 |
OBJ element; |
|
4122 | 506 |
|
14632 | 507 |
element = srcP[0]; |
508 |
dstP[0] = element; |
|
509 |
__STORE_SPC(nObj, element, spc); |
|
510 |
element = srcP[1]; |
|
511 |
dstP[1] = element; |
|
512 |
__STORE_SPC(nObj, element, spc); |
|
513 |
element = srcP[2]; |
|
514 |
dstP[2] = element; |
|
515 |
__STORE_SPC(nObj, element, spc); |
|
516 |
element = srcP[3]; |
|
517 |
dstP[3] = element; |
|
518 |
__STORE_SPC(nObj, element, spc); |
|
519 |
srcP += 4; |
|
520 |
dstP += 4; |
|
521 |
nIndex -= 4; |
|
522 |
} |
|
393 | 523 |
#endif |
14632 | 524 |
while (nIndex--) { |
525 |
OBJ element; |
|
4122 | 526 |
|
14632 | 527 |
element = *srcP++; |
528 |
*dstP++ = element; |
|
529 |
__STORE_SPC(nObj, element, spc); |
|
530 |
} |
|
531 |
*dstP = something; |
|
532 |
__STORE_SPC(nObj, something, spc); |
|
533 |
RETURN ( nObj ); |
|
534 |
} |
|
1 | 535 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
536 |
%}. |
1 | 537 |
^ super copyWith:something |
538 |
! ! |
|
539 |
||
216 | 540 |
!Array methodsFor:'enumerating'! |
1 | 541 |
|
10796
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
542 |
addAllNonNilElementsTo:aCollection |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
543 |
"add all nonNil elements of the receiver to aCollection. |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
544 |
Return aCollection. |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
545 |
Redefined here for slightly more speed." |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
546 |
|
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
547 |
|stop "{ Class: SmallInteger }"| |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
548 |
|
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
549 |
stop := self size. |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
550 |
1 to:stop do:[:idx | |
14632 | 551 |
|each| |
552 |
each := self at:idx. |
|
553 |
each notNil ifTrue:[ |
|
554 |
aCollection add:each. |
|
555 |
]. |
|
10796
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
556 |
]. |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
557 |
^ aCollection |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
558 |
|
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
559 |
" |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
560 |
#(1 2 3 4 5 1 2 3 symbol 'string' nil) addAllNonNilElementsTo:Set new |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
561 |
" |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
562 |
! |
08a9ee8cf317
Do not add nil elements to a Set in #asSet and #asIdentitySet
Stefan Vogel <sv@exept.de>
parents:
10089
diff
changeset
|
563 |
|
554 | 564 |
addAllTo:aCollection |
565 |
"add all elements of the receiver to aCollection. |
|
8603 | 566 |
Return aCollection. |
567 |
Redefined here for slightly more speed." |
|
554 | 568 |
|
569 |
|stop "{ Class: SmallInteger }"| |
|
570 |
||
571 |
stop := self size. |
|
572 |
1 to:stop do:[:idx | |
|
14632 | 573 |
aCollection add:(self at:idx) |
554 | 574 |
]. |
575 |
^ aCollection |
|
576 |
! |
|
577 |
||
578 |
do:aBlock |
|
579 |
"evaluate the argument, aBlock for each element in the collection. |
|
4122 | 580 |
- reimplemented for speed, since this is used by many higher |
581 |
level collections" |
|
554 | 582 |
|
2202 | 583 |
| sz "{ Class: SmallInteger }"| |
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
584 |
|
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
585 |
sz := self size. |
554 | 586 |
%{ |
587 |
REGISTER OBJFUNC codeVal; |
|
14687 | 588 |
REGISTER INT index; |
589 |
unsigned INT nIndex; |
|
554 | 590 |
static struct inlineCache val = _ILC1; |
591 |
REGISTER OBJ rHome; |
|
14687 | 592 |
INT actualSize; |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
593 |
|
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
594 |
{ |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
595 |
OBJ mySelf = self; |
554 | 596 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
597 |
index = __intVal(__ClassInstPtr(__qClass(mySelf))->c_ninstvars); |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
598 |
actualSize = __BYTES2OBJS__(__qSize(mySelf) - OHDR_SIZE); |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
599 |
} |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
600 |
|
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
601 |
nIndex = index + __intVal(sz); |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
602 |
if (nIndex <= actualSize) { |
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
603 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
604 |
if (__isBlockLike(aBlock) |
8913 | 605 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
606 |
{ |
2915 | 607 |
/* |
608 |
* the most common case: a static compiled block, with home on the stack ... |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
609 |
*/ |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
610 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
611 |
|
2915 | 612 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 613 |
#ifdef PARANOIA |
2915 | 614 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 615 |
#endif |
616 |
) { |
|
2254 | 617 |
|
554 | 618 |
#ifdef NEW_BLOCK_CALL |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
619 |
# define BLOCK_ARG aBlock |
554 | 620 |
#else |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
621 |
# define BLOCK_ARG rHome |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
622 |
REGISTER OBJ rHome; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
623 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
624 |
rHome = __BlockInstPtr(aBlock)->b_home; |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
625 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
626 |
#endif |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
627 |
{ |
2216 | 628 |
|
2878 | 629 |
/* |
630 |
* boy; what an ugly looking piece of code ... |
|
631 |
* however, this software pipelined thing has no taken conditional |
|
632 |
* branches in the normal case and is almost twice as fast to even |
|
633 |
* what an unrolling optimizing compiler produces from the loop below ... |
|
634 |
* notice, that those gotos expand to forward branches (which are predicted |
|
635 |
* as NOT taken by most machines ... which is exactly what we want) |
|
636 |
*/ |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
637 |
REGISTER OBJ el; |
8919 | 638 |
#ifdef __UNROLL_LOOPS__ |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
639 |
|
2216 | 640 |
{ |
641 |
int i8; |
|
642 |
||
643 |
while ((i8 = index+8) < nIndex) { |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
644 |
el = __InstPtr(self)->i_instvars[index]; |
2216 | 645 |
if (InterruptPending != nil) goto interrupt0; |
646 |
continue0: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
647 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
648 |
el = __InstPtr(self)->i_instvars[index+1]; |
2216 | 649 |
if (InterruptPending != nil) goto interrupt1; |
650 |
continue1: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
651 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
652 |
el = __InstPtr(self)->i_instvars[index+2]; |
2216 | 653 |
if (InterruptPending != nil) goto interrupt2; |
654 |
continue2: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
655 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
656 |
el = __InstPtr(self)->i_instvars[index+3]; |
2216 | 657 |
if (InterruptPending != nil) goto interrupt3; |
658 |
continue3: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
659 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
660 |
el = __InstPtr(self)->i_instvars[index+4]; |
2216 | 661 |
if (InterruptPending != nil) goto interrupt4; |
662 |
continue4: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
663 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
664 |
el = __InstPtr(self)->i_instvars[index+5]; |
2216 | 665 |
if (InterruptPending != nil) goto interrupt5; |
666 |
continue5: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
667 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
668 |
el = __InstPtr(self)->i_instvars[index+6]; |
2216 | 669 |
if (InterruptPending != nil) goto interrupt6; |
670 |
continue6: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
671 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
672 |
el = __InstPtr(self)->i_instvars[index+7]; |
2216 | 673 |
if (InterruptPending != nil) goto interrupt7; |
674 |
continue7: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
675 |
(*codeVal)(BLOCK_ARG, el); |
2216 | 676 |
index = i8; |
677 |
} |
|
678 |
} |
|
8919 | 679 |
#endif /* __UNROLL_LOOPS__ */ |
2216 | 680 |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
681 |
for (; index < nIndex; index++) { |
2217 | 682 |
el = __InstPtr(self)->i_instvars[index]; |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
683 |
if (InterruptPending != nil) goto interruptX; |
2915 | 684 |
continueX: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
685 |
(*codeVal)(BLOCK_ARG, el); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
686 |
} |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
687 |
RETURN (self); |
2216 | 688 |
|
8919 | 689 |
#ifdef __UNROLL_LOOPS__ |
2216 | 690 |
interrupt0: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
691 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
692 |
el = __InstPtr(self)->i_instvars[index]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
693 |
goto continue0; |
2216 | 694 |
interrupt1: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
695 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
696 |
el = __InstPtr(self)->i_instvars[index+1]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
697 |
goto continue1; |
2216 | 698 |
interrupt2: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
699 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
700 |
el = __InstPtr(self)->i_instvars[index+2]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
701 |
goto continue2; |
2216 | 702 |
interrupt3: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
703 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
704 |
el = __InstPtr(self)->i_instvars[index+3]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
705 |
goto continue3; |
2216 | 706 |
interrupt4: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
707 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
708 |
el = __InstPtr(self)->i_instvars[index+4]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
709 |
goto continue4; |
2216 | 710 |
interrupt5: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
711 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
712 |
el = __InstPtr(self)->i_instvars[index+5]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
713 |
goto continue5; |
2216 | 714 |
interrupt6: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
715 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
716 |
el = __InstPtr(self)->i_instvars[index+6]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
717 |
goto continue6; |
2216 | 718 |
interrupt7: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
719 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
720 |
el = __InstPtr(self)->i_instvars[index+7]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
721 |
goto continue7; |
8919 | 722 |
#endif /* __UNROLL_LOOPS__ */ |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
723 |
interruptX: |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
724 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
725 |
el = __InstPtr(self)->i_instvars[index]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
726 |
goto continueX; |
3500 | 727 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
728 |
} |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
729 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
730 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
731 |
/* |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
732 |
* sorry, must check code-pointer in the loop |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
733 |
* it could be recompiled or flushed |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
734 |
*/ |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
735 |
# undef BLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
736 |
#ifdef NEW_BLOCK_CALL |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
737 |
# define BLOCK_ARG aBlock |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
738 |
# define IBLOCK_ARG nil |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
739 |
#else |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
740 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
741 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
742 |
#endif |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
743 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
744 |
for (; index < nIndex; index++) { |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
745 |
REGISTER OBJFUNC codeVal; |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
746 |
|
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
747 |
if (InterruptPending != nil) __interruptL(@line); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
748 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
749 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
750 |
(*codeVal)(BLOCK_ARG, __InstPtr(self)->i_instvars[index]); |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
751 |
} else { |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
752 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
753 |
/* |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
754 |
* arg is a compiled block with bytecode - |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
755 |
* directly call interpreter without going through Block>>value |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
756 |
*/ |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
757 |
#ifdef PASS_ARG_POINTER |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
758 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &(__InstPtr(self)->i_instvars[index])); |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
759 |
#else |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
760 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __InstPtr(self)->i_instvars[index]); |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
761 |
#endif |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
762 |
} else { |
14632 | 763 |
(*val.ilc_func)(aBlock, |
764 |
@symbol(value:), |
|
765 |
nil, &val, |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
766 |
__InstPtr(self)->i_instvars[index]); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
767 |
} |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
768 |
} |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
769 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
770 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
771 |
# undef BLOCK_ARG |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
772 |
# undef IBLOCK_ARG |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
773 |
|
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
774 |
RETURN (self ); |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
775 |
} |
554 | 776 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
777 |
/* |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
778 |
* not a block - send it #value: |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
779 |
*/ |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
780 |
for (; index < nIndex; index++) { |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
781 |
if (InterruptPending != nil) __interruptL(@line); |
14632 | 782 |
// console_printf("el%d -> %"_lx_"\n", index, (long)(__InstPtr(self)->i_instvars[index])); |
783 |
(*val.ilc_func)(aBlock, |
|
784 |
@symbol(value:), |
|
785 |
nil, &val, |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
786 |
__InstPtr(self)->i_instvars[index]); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
787 |
} |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
788 |
RETURN ( self ); |
554 | 789 |
} |
14632 | 790 |
/* |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
791 |
* I am something, not handled here |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
792 |
*/ |
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
793 |
%}. |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
794 |
^ super do:aBlock |
554 | 795 |
! |
796 |
||
1 | 797 |
from:start to:stop do:aBlock |
798 |
"evaluate the argument, aBlock for the elements starting at index start |
|
799 |
up to (and including) stop in the collection. |
|
4122 | 800 |
- reimplemented for speed, since this is used by many higher |
801 |
level collections" |
|
1 | 802 |
|
803 |
%{ |
|
804 |
REGISTER OBJFUNC codeVal; |
|
14687 | 805 |
REGISTER INT index; |
2 | 806 |
REGISTER OBJ rHome; |
2052 | 807 |
OBJ slf; |
14687 | 808 |
INT nIndex, nInsts; |
1 | 809 |
static struct inlineCache val = _ILC1; |
14687 | 810 |
INT indexHigh; |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
811 |
OBJ myClass; |
1 | 812 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
813 |
slf = self; |
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
814 |
myClass = __qClass(slf); |
5347
21b418ac4cc3
oops: from:to:do: failed badly when stopIndex was < startIndex.
Claus Gittinger <cg@exept.de>
parents:
5049
diff
changeset
|
815 |
|
21b418ac4cc3
oops: from:to:do: failed badly when stopIndex was < startIndex.
Claus Gittinger <cg@exept.de>
parents:
5049
diff
changeset
|
816 |
if ( __bothSmallInteger(start, stop) |
21b418ac4cc3
oops: from:to:do: failed badly when stopIndex was < startIndex.
Claus Gittinger <cg@exept.de>
parents:
5049
diff
changeset
|
817 |
&& ((index = __intVal(start)) > 0) ) { |
6497 | 818 |
indexHigh = __intVal(stop); |
819 |
nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE); |
|
820 |
if (myClass != @global(Array)) { |
|
821 |
nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
822 |
index += nInsts; |
|
823 |
indexHigh += nInsts; |
|
824 |
} |
|
825 |
if (indexHigh <= nIndex) { |
|
826 |
OBJ __aBlock = aBlock; |
|
14687 | 827 |
INT n; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
828 |
|
6497 | 829 |
index--; /* 0-based */ |
830 |
n = indexHigh - index; |
|
3484 | 831 |
|
6497 | 832 |
if (__isBlockLike(__aBlock) |
8913 | 833 |
&& (__BlockInstPtr(__aBlock)->b_nargs == __mkSmallInteger(1))) { |
6497 | 834 |
{ |
835 |
/* |
|
836 |
* the most common case: a static compiled block, with home on the stack ... |
|
837 |
*/ |
|
838 |
REGISTER OBJFUNC codeVal; |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
839 |
|
6497 | 840 |
if (((codeVal = __BlockInstPtr(__aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 841 |
#ifdef PARANOIA |
6497 | 842 |
&& (! ((INT)(__BlockInstPtr(__aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 843 |
#endif |
6497 | 844 |
) { |
11 | 845 |
#ifdef NEW_BLOCK_CALL |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
846 |
# define BLOCK_ARG aBlock |
11 | 847 |
#else |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
848 |
# define BLOCK_ARG rHome |
6497 | 849 |
REGISTER OBJ rHome; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
850 |
|
6497 | 851 |
rHome = __BlockInstPtr(__aBlock)->b_home; |
852 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
853 |
#endif |
6497 | 854 |
{ |
855 |
REGISTER OBJ el; |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
856 |
|
8919 | 857 |
#ifdef __UNROLL_LOOPS__ |
6497 | 858 |
/* |
859 |
* boy; what an ugly looking piece of code ... |
|
860 |
* however, this software pipelined thing has no taken conditional |
|
861 |
* branches in the normal case and is almost twice as fast to even |
|
862 |
* what an unrolling optimizing compiler produces from the loop below ... |
|
863 |
* notice, that those gotos expand to forward branches (which are predicted |
|
864 |
* as NOT taken by most machines ... which is exactly what we want) |
|
865 |
*/ |
|
866 |
{ |
|
867 |
while ( n >= 8) { |
|
868 |
el = __InstPtr(self)->i_instvars[index]; |
|
869 |
if (InterruptPending != nil) goto interrupt0; |
|
870 |
continue0: |
|
871 |
(*codeVal)(BLOCK_ARG, el); |
|
872 |
el = __InstPtr(self)->i_instvars[index+1]; |
|
873 |
if (InterruptPending != nil) goto interrupt1; |
|
874 |
continue1: |
|
875 |
(*codeVal)(BLOCK_ARG, el); |
|
876 |
el = __InstPtr(self)->i_instvars[index+2]; |
|
877 |
if (InterruptPending != nil) goto interrupt2; |
|
878 |
continue2: |
|
879 |
(*codeVal)(BLOCK_ARG, el); |
|
880 |
el = __InstPtr(self)->i_instvars[index+3]; |
|
881 |
if (InterruptPending != nil) goto interrupt3; |
|
882 |
continue3: |
|
883 |
(*codeVal)(BLOCK_ARG, el); |
|
884 |
el = __InstPtr(self)->i_instvars[index+4]; |
|
885 |
if (InterruptPending != nil) goto interrupt4; |
|
886 |
continue4: |
|
887 |
(*codeVal)(BLOCK_ARG, el); |
|
888 |
el = __InstPtr(self)->i_instvars[index+5]; |
|
889 |
if (InterruptPending != nil) goto interrupt5; |
|
890 |
continue5: |
|
891 |
(*codeVal)(BLOCK_ARG, el); |
|
892 |
el = __InstPtr(self)->i_instvars[index+6]; |
|
893 |
if (InterruptPending != nil) goto interrupt6; |
|
894 |
continue6: |
|
895 |
(*codeVal)(BLOCK_ARG, el); |
|
896 |
el = __InstPtr(self)->i_instvars[index+7]; |
|
897 |
if (InterruptPending != nil) goto interrupt7; |
|
898 |
continue7: |
|
899 |
(*codeVal)(BLOCK_ARG, el); |
|
900 |
n -= 8; |
|
901 |
index += 8; |
|
902 |
} |
|
8919 | 903 |
# ifdef __UNROLL_LOOPS2__ /* this makes small loops slower */ |
6497 | 904 |
if (n >= 4) { |
905 |
el = __InstPtr(self)->i_instvars[index]; |
|
906 |
if (InterruptPending != nil) goto interrupt0b; |
|
907 |
continue0b: |
|
908 |
(*codeVal)(BLOCK_ARG, el); |
|
909 |
el = __InstPtr(self)->i_instvars[index+1]; |
|
910 |
if (InterruptPending != nil) goto interrupt1b; |
|
911 |
continue1b: |
|
912 |
(*codeVal)(BLOCK_ARG, el); |
|
913 |
el = __InstPtr(self)->i_instvars[index+2]; |
|
914 |
if (InterruptPending != nil) goto interrupt2b; |
|
915 |
continue2b: |
|
916 |
(*codeVal)(BLOCK_ARG, el); |
|
917 |
el = __InstPtr(self)->i_instvars[index+3]; |
|
918 |
if (InterruptPending != nil) goto interrupt3b; |
|
919 |
continue3b: |
|
920 |
(*codeVal)(BLOCK_ARG, el); |
|
921 |
n -= 4; |
|
922 |
index += 4; |
|
923 |
} |
|
924 |
if (n >= 2) { |
|
925 |
el = __InstPtr(self)->i_instvars[index]; |
|
926 |
if (InterruptPending != nil) goto interrupt0c; |
|
927 |
continue0c: |
|
928 |
(*codeVal)(BLOCK_ARG, el); |
|
929 |
el = __InstPtr(self)->i_instvars[index+1]; |
|
930 |
if (InterruptPending != nil) goto interrupt1c; |
|
931 |
continue1c: |
|
932 |
(*codeVal)(BLOCK_ARG, el); |
|
933 |
n -= 2; |
|
934 |
index += 2; |
|
935 |
} |
|
8919 | 936 |
# endif /* __UNROLL_LOOPS2__ */ |
6497 | 937 |
} |
8919 | 938 |
#endif /* __UNROLL_LOOPS__ */ |
6497 | 939 |
while (n > 0) { |
940 |
el = __InstPtr(self)->i_instvars[index]; |
|
941 |
if (InterruptPending != nil) goto interruptX; |
|
942 |
continueX: |
|
943 |
(*codeVal)(BLOCK_ARG, el); |
|
944 |
n--; |
|
945 |
index++; |
|
946 |
} |
|
947 |
RETURN (self); |
|
2216 | 948 |
|
8919 | 949 |
#ifdef __UNROLL_LOOPS__ |
6497 | 950 |
interrupt0: |
951 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index]; |
|
952 |
goto continue0; |
|
953 |
interrupt1: |
|
954 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+1]; |
|
955 |
goto continue1; |
|
956 |
interrupt2: |
|
957 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+2]; |
|
958 |
goto continue2; |
|
959 |
interrupt3: |
|
960 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+3]; |
|
961 |
goto continue3; |
|
962 |
interrupt4: |
|
963 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+4]; |
|
964 |
goto continue4; |
|
965 |
interrupt5: |
|
966 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+5]; |
|
967 |
goto continue5; |
|
968 |
interrupt6: |
|
969 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+6]; |
|
970 |
goto continue6; |
|
971 |
interrupt7: |
|
972 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+7]; |
|
973 |
goto continue7; |
|
3484 | 974 |
|
8919 | 975 |
# ifdef __UNROLL_LOOPS2__ |
6497 | 976 |
interrupt0b: |
977 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index]; |
|
978 |
goto continue0b; |
|
979 |
interrupt1b: |
|
980 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+1]; |
|
981 |
goto continue1b; |
|
982 |
interrupt2b: |
|
983 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+2]; |
|
984 |
goto continue2b; |
|
985 |
interrupt3b: |
|
986 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+3]; |
|
987 |
goto continue3b; |
|
3484 | 988 |
|
6497 | 989 |
interrupt0c: |
990 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index]; |
|
991 |
goto continue0c; |
|
992 |
interrupt1c: |
|
993 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+1]; |
|
994 |
goto continue1c; |
|
8919 | 995 |
# endif /* __UNROLL_LOOPS2__ */ |
996 |
#endif /* __UNROLL_LOOPS__ */ |
|
6497 | 997 |
interruptX: |
998 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index]; |
|
999 |
goto continueX; |
|
1000 |
} |
|
1001 |
} |
|
1002 |
} |
|
370 | 1003 |
|
6497 | 1004 |
/* |
1005 |
* sorry, must check code-pointer in the loop |
|
1006 |
* it could be recompiled or flushed |
|
1007 |
*/ |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1008 |
# undef BLOCK_ARG |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1009 |
#ifdef NEW_BLOCK_CALL |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1010 |
# define BLOCK_ARG aBlock |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1011 |
# define IBLOCK_ARG nil |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1012 |
#else |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1013 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1014 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
11 | 1015 |
#endif |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1016 |
|
6497 | 1017 |
while (n > 0) { |
1018 |
REGISTER OBJFUNC codeVal; |
|
1019 |
OBJ el; |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1020 |
|
6497 | 1021 |
el = __InstPtr(self)->i_instvars[index]; |
1022 |
if (InterruptPending != nil) { |
|
1023 |
__interruptL(@line); |
|
1024 |
el = __InstPtr(self)->i_instvars[index]; |
|
1025 |
} |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1026 |
|
6497 | 1027 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
1028 |
(*codeVal)(BLOCK_ARG, el); |
|
1029 |
} else { |
|
1030 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
1031 |
/* |
|
1032 |
* arg is a compiled block with bytecode - |
|
1033 |
* directly call interpreter without going through Block>>value |
|
1034 |
*/ |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1035 |
#ifdef PASS_ARG_POINTER |
6497 | 1036 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &el); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1037 |
#else |
6497 | 1038 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, el); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1039 |
#endif |
6497 | 1040 |
} else { |
14632 | 1041 |
(*val.ilc_func)(aBlock, |
1042 |
@symbol(value:), |
|
1043 |
nil, &val, |
|
6497 | 1044 |
el); |
1045 |
} |
|
1046 |
} |
|
1047 |
n--; |
|
1048 |
index++; |
|
1049 |
} |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1050 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1051 |
# undef BLOCK_ARG |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1052 |
# undef IBLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1053 |
|
6497 | 1054 |
RETURN (self ); |
1055 |
} |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1056 |
|
6497 | 1057 |
/* |
1058 |
* not a block - send it #value: |
|
1059 |
*/ |
|
1060 |
while (n > 0) { |
|
1061 |
if (InterruptPending != nil) __interruptL(@line); |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1062 |
|
14632 | 1063 |
(*val.ilc_func)(aBlock, |
1064 |
@symbol(value:), |
|
1065 |
nil, &val, |
|
6497 | 1066 |
__InstPtr(self)->i_instvars[index]); |
1067 |
n--; |
|
1068 |
index++; |
|
1069 |
} |
|
1070 |
RETURN ( self ); |
|
1071 |
} |
|
1 | 1072 |
} |
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1073 |
%}. |
1 | 1074 |
^ super from:start to:stop do:aBlock |
5347
21b418ac4cc3
oops: from:to:do: failed badly when stopIndex was < startIndex.
Claus Gittinger <cg@exept.de>
parents:
5049
diff
changeset
|
1075 |
|
1 | 1076 |
! |
1077 |
||
42 | 1078 |
from:start to:stop reverseDo:aBlock |
1079 |
"evaluate the argument, aBlock for the elements starting at index start |
|
1080 |
up to (and including) stop in the collection. Step in reverse order. |
|
1081 |
- reimplemented for speed" |
|
1082 |
||
1083 |
%{ |
|
1084 |
REGISTER OBJFUNC codeVal; |
|
14687 | 1085 |
REGISTER INT index; |
42 | 1086 |
REGISTER OBJ rHome; |
14687 | 1087 |
INT nIndex; |
42 | 1088 |
static struct inlineCache val = _ILC1; |
14687 | 1089 |
INT indexLow, indexHigh; |
42 | 1090 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
1091 |
if (__bothSmallInteger(start, stop) |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1092 |
&& (__qClass(self) == @global(Array)) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1093 |
&& ((indexLow = __intVal(start)) > 0)) { |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1094 |
indexHigh = __intVal(stop); |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1095 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1096 |
if (indexHigh <= nIndex) { |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1097 |
indexLow--; |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1098 |
indexHigh--; |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1099 |
|
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1100 |
if (__isBlockLike(aBlock) |
8913 | 1101 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1102 |
# undef BLOCK_ARG |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1103 |
#ifdef NEW_BLOCK_CALL |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1104 |
# define BLOCK_ARG aBlock |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1105 |
# define IBLOCK_ARG nil |
42 | 1106 |
#else |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1107 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1108 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1109 |
#endif |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1110 |
|
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1111 |
for (index=indexHigh; index >= indexLow; index--) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1112 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1113 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1114 |
if (InterruptPending != nil) __interruptL(@line); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1115 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1116 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1117 |
(*codeVal)(BLOCK_ARG, __InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1118 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1119 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1120 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1121 |
* arg is a compiled block with bytecode - |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1122 |
* directly call interpreter without going through Block>>value |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1123 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1124 |
#ifdef PASS_ARG_POINTER |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1125 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &(__InstPtr(self)->i_instvars[index])); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1126 |
#else |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1127 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __InstPtr(self)->i_instvars[index]); |
42 | 1128 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1129 |
} else { |
14632 | 1130 |
(*val.ilc_func)(aBlock, |
1131 |
@symbol(value:), |
|
1132 |
nil, &val, |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1133 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1134 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1135 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1136 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1137 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1138 |
# undef BLOCK_ARG |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1139 |
# undef IBLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1140 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1141 |
RETURN (self ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1142 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1143 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1144 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1145 |
* not a block - send it #value: |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1146 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1147 |
for (index=indexHigh; index >= indexLow; index--) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1148 |
if (InterruptPending != nil) __interruptL(@line); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1149 |
|
14632 | 1150 |
(*val.ilc_func)(aBlock, |
1151 |
@symbol(value:), |
|
1152 |
nil, &val, |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1153 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1154 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1155 |
RETURN ( self ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1156 |
} |
42 | 1157 |
} |
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1158 |
%}. |
42 | 1159 |
^ super from:start to:stop reverseDo:aBlock |
1160 |
! |
|
1161 |
||
554 | 1162 |
keysAndValuesDo:aBlock |
1163 |
"evaluate the argument, aBlock for each element in the collection. |
|
1164 |
Pass both index and element to the block. |
|
1165 |
- reimplemented for speed" |
|
1166 |
||
1167 |
%{ |
|
1168 |
REGISTER OBJFUNC codeVal; |
|
8913 | 1169 |
REGISTER INT index; |
554 | 1170 |
static struct inlineCache val2 = _ILC2; |
1171 |
REGISTER OBJ rHome; |
|
14687 | 1172 |
INT actualSize; |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1173 |
OBJ myClass; |
554 | 1174 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1175 |
myClass = __qClass(self); |
8913 | 1176 |
if ((__ClassInstPtr(myClass)->c_ninstvars) == __mkSmallInteger(0)) { |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1177 |
|
2915 | 1178 |
actualSize = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
1179 |
index = 0; |
|
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1180 |
|
2915 | 1181 |
if (index < actualSize) { |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1182 |
if (__isBlockLike(aBlock) |
8913 | 1183 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(2))) { |
2915 | 1184 |
{ |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1185 |
/* |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1186 |
* the most common case: a static compiled block, with home on the stack ... |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1187 |
*/ |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1188 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1189 |
|
2915 | 1190 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 1191 |
#ifdef PARANOIA |
2915 | 1192 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 1193 |
#endif |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1194 |
) { |
2254 | 1195 |
|
554 | 1196 |
#ifdef NEW_BLOCK_CALL |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1197 |
# define BLOCK_ARG aBlock |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1198 |
#else |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1199 |
# define BLOCK_ARG rHome |
2915 | 1200 |
REGISTER OBJ rHome; |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1201 |
|
2915 | 1202 |
rHome = __BlockInstPtr(aBlock)->b_home; |
1203 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1204 |
#endif |
2915 | 1205 |
{ |
2878 | 1206 |
OBJ el; |
1207 |
||
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1208 |
while (index < actualSize) { |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1209 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1210 |
el = __InstPtr(self)->i_instvars[index]; |
2915 | 1211 |
if (InterruptPending != nil) goto interruptX; |
2878 | 1212 |
continueX: |
2915 | 1213 |
index++; |
8913 | 1214 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(index), el); |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1215 |
} |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1216 |
RETURN (self); |
2878 | 1217 |
|
1218 |
interruptX: |
|
14632 | 1219 |
__interruptL(@line); |
2878 | 1220 |
el = __InstPtr(self)->i_instvars[index]; |
1221 |
goto continueX; |
|
2915 | 1222 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1223 |
} |
2915 | 1224 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1225 |
|
2915 | 1226 |
/* |
1227 |
* sorry, must check code-pointer in the loop |
|
1228 |
* it could be recompiled or flushed |
|
1229 |
*/ |
|
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1230 |
# undef BLOCK_ARG |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1231 |
#ifdef NEW_BLOCK_CALL |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1232 |
# define BLOCK_ARG aBlock |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1233 |
# define IBLOCK_ARG nil |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1234 |
#else |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1235 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1236 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1237 |
#endif |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1238 |
|
2915 | 1239 |
while (index < actualSize) { |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1240 |
REGISTER OBJFUNC codeVal; |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1241 |
OBJ el; |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1242 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1243 |
if (InterruptPending != nil) __interruptL(@line); |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1244 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1245 |
el = __InstPtr(self)->i_instvars[index]; |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1246 |
index++; |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1247 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
8913 | 1248 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(index), el); |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1249 |
} else { |
2915 | 1250 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1251 |
/* |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1252 |
* arg is a compiled block with bytecode - |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1253 |
* directly call interpreter without going through Block>>value |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1254 |
*/ |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1255 |
#ifdef PASS_ARG_POINTER |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1256 |
{ |
2915 | 1257 |
OBJ t[2]; |
554 | 1258 |
|
8913 | 1259 |
t[0] = __mkSmallInteger(index); |
2915 | 1260 |
t[1] = el; |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1261 |
|
2915 | 1262 |
__interpret(aBlock, 2, nil, IBLOCK_ARG, nil, nil, t); |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1263 |
} |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1264 |
#else |
8913 | 1265 |
__interpret(aBlock, 2, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(index), el); |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1266 |
#endif |
2915 | 1267 |
} else { |
14632 | 1268 |
(*val2.ilc_func)(aBlock, |
1269 |
@symbol(value:value:), |
|
1270 |
nil, &val2, |
|
8913 | 1271 |
__mkSmallInteger(index), |
2915 | 1272 |
el); |
1273 |
} |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1274 |
} |
2915 | 1275 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1276 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1277 |
# undef BLOCK_ARG |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1278 |
# undef IBLOCK_ARG |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1279 |
|
2915 | 1280 |
RETURN (self ); |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
1281 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1282 |
|
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
1283 |
/* |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1284 |
* not a block - send it #value: |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
1285 |
*/ |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1286 |
while (index < actualSize) { |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1287 |
OBJ el; |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
1288 |
|
2915 | 1289 |
if (InterruptPending != nil) __interruptL(@line); |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
1290 |
|
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1291 |
el = __InstPtr(self)->i_instvars[index]; |
2915 | 1292 |
index++; |
14632 | 1293 |
(*val2.ilc_func)(aBlock, |
1294 |
@symbol(value:value:), |
|
1295 |
nil, &val2, |
|
8913 | 1296 |
__mkSmallInteger(index), |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1297 |
el); |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1298 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1299 |
RETURN ( self ); |
2915 | 1300 |
} |
554 | 1301 |
} |
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1302 |
%}. |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1303 |
^ super keysAndValuesDo:aBlock |
554 | 1304 |
! |
1305 |
||
14632 | 1306 |
modifyingTraverse:aBlock |
1307 |
"Evaluate aBlock for every element that is not an Array, |
|
11167 | 1308 |
and recursively traverse Arrays. |
1309 |
||
1310 |
aBlock may return the original element or a new element. |
|
1311 |
If a new element is returned, the element is changed to the new element." |
|
1312 |
||
14632 | 1313 |
self |
1314 |
keysAndValuesDo:[:eachIndex :eachElement | |
|
1315 |
eachElement isArray ifTrue:[ |
|
1316 |
eachElement modifyingTraverse:aBlock |
|
1317 |
] ifFalse:[ |
|
1318 |
|newElement| |
|
1319 |
||
1320 |
newElement := aBlock value:eachElement. |
|
1321 |
newElement ~~ eachElement ifTrue:[ |
|
1322 |
self at:eachIndex put:newElement. |
|
1323 |
]. |
|
1324 |
] |
|
1325 |
]. |
|
11167 | 1326 |
|
1327 |
" |
|
1328 |
example: replace all elements which are 10 with: 'changed' |
|
1329 |
||
14632 | 1330 |
#(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) copy |
1331 |
modifyingTraverse:[:el | |
|
1332 |
el = 10 ifTrue:['changed'] ifFalse:[el] |
|
1333 |
]; |
|
1334 |
inspect |
|
11167 | 1335 |
" |
1336 |
! |
|
1337 |
||
543 | 1338 |
reverseDo:aBlock |
1339 |
"evaluate the argument, aBlock for each element in the collection in reverse order. |
|
1340 |
- reimplemented for speed" |
|
1 | 1341 |
|
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1342 |
|home sz "{ Class: SmallInteger }" | |
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1343 |
|
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1344 |
sz := self size. |
1 | 1345 |
%{ |
1346 |
REGISTER OBJFUNC codeVal; |
|
14687 | 1347 |
REGISTER INT index; |
1348 |
unsigned INT nIndex; |
|
1349 |
INT endIndex; |
|
1 | 1350 |
static struct inlineCache val = _ILC1; |
14687 | 1351 |
INT actualSize; |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1352 |
OBJ myClass; |
1 | 1353 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1354 |
myClass = __qClass(self); |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
1355 |
{ |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1356 |
endIndex = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1357 |
actualSize = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1358 |
nIndex = endIndex + __intVal(sz); |
543 | 1359 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1360 |
if (nIndex <= actualSize) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1361 |
if (__isBlockLike(aBlock) |
8913 | 1362 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1363 |
# undef BLOCK_ARG |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1364 |
#ifdef NEW_BLOCK_CALL |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1365 |
# define BLOCK_ARG aBlock |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1366 |
# define IBLOCK_ARG nil |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1367 |
#else |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1368 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1369 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1370 |
#endif |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1371 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1372 |
for (index=nIndex-1; index >= endIndex; index--) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1373 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1374 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1375 |
if (InterruptPending != nil) __interruptL(@line); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1376 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1377 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1378 |
(*codeVal)(BLOCK_ARG, __InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1379 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1380 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1381 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1382 |
* arg is a compiled block with bytecode - |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1383 |
* directly call interpreter without going through Block>>value |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1384 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1385 |
#ifdef PASS_ARG_POINTER |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1386 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &(__InstPtr(self)->i_instvars[index])); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1387 |
#else |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1388 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __InstPtr(self)->i_instvars[index]); |
11 | 1389 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1390 |
} else { |
14632 | 1391 |
(*val.ilc_func)(aBlock, |
1392 |
@symbol(value:), |
|
1393 |
nil, &val, |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1394 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1395 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1396 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1397 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1398 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1399 |
# undef BLOCK_ARG |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1400 |
# undef IBLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1401 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1402 |
RETURN (self ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1403 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1404 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1405 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1406 |
* not a block - send it #value: |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1407 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1408 |
for (index=nIndex-1; index >= endIndex; index--) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1409 |
if (InterruptPending != nil) __interruptL(@line); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1410 |
|
14632 | 1411 |
(*val.ilc_func)(aBlock, |
1412 |
@symbol(value:), |
|
1413 |
nil, &val, |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1414 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1415 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1416 |
RETURN ( self ); |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1417 |
} |
1 | 1418 |
} |
543 | 1419 |
%}. |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1420 |
^ super reverseDo:aBlock |
11 | 1421 |
! |
1422 |
||
328 | 1423 |
traverse:aBlock |
14632 | 1424 |
"Evaluate aBlock for every element that is not an Array, |
1123 | 1425 |
and recursively traverse Arrays. |
328 | 1426 |
Implemented here to support better search for selectors in |
1427 |
literal arrays - might be a good idea to move it up in the collection |
|
1428 |
hierarchy, since this may be a useful method for other collections |
|
1429 |
as well." |
|
1430 |
||
1431 |
self do: [:el | |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1432 |
el isArray |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1433 |
ifTrue: [el traverse: aBlock] |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1434 |
ifFalse: [aBlock value: el]] |
328 | 1435 |
|
1436 |
" |
|
1437 |
example: flattening an Array: |
|
1438 |
||
1439 |
|s| |
|
1440 |
||
1441 |
s := WriteStream on:Array new. |
|
1442 |
#(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) traverse:[:el | s nextPut:el]. |
|
14632 | 1443 |
s contents |
328 | 1444 |
" |
1123 | 1445 |
" |
1446 |
example: deep search |
|
1447 |
||
14632 | 1448 |
#(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) traverse:[:el | |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1449 |
el == 10 ifTrue:[Transcript showCR:'found'] |
1123 | 1450 |
] |
1451 |
" |
|
1452 |
||
1453 |
"Modified: 26.3.1996 / 17:08:10 / cg" |
|
543 | 1454 |
! ! |
1455 |
||
1456 |
!Array methodsFor:'filling & replacing'! |
|
1457 |
||
554 | 1458 |
from:index1 to:index2 put:anObject |
1459 |
"reimplemented for speed if receiver is an Array" |
|
1460 |
||
1461 |
%{ /* NOCONTEXT */ |
|
1462 |
||
14687 | 1463 |
REGISTER INT index; |
1464 |
unsigned INT nIndex; |
|
1465 |
unsigned INT endIndex; |
|
554 | 1466 |
REGISTER OBJ *dst; |
1467 |
||
1468 |
if ((__qClass(self) == Array) |
|
1469 |
&& __bothSmallInteger(index1, index2)) { |
|
1133 | 1470 |
index = __intVal(index1) - 1; |
554 | 1471 |
if (index >= 0) { |
1472 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1133 | 1473 |
endIndex = __intVal(index2) - 1; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1474 |
|
951
2dd898849a8a
directly call __new if quick allocation fails;
Claus Gittinger <cg@exept.de>
parents:
946
diff
changeset
|
1475 |
if ((endIndex >= index) && (endIndex < nIndex)) { |
1133 | 1476 |
dst = &(__InstPtr(self)->i_instvars[index]); |
554 | 1477 |
#ifdef memset4 |
2865 | 1478 |
{ |
1479 |
int n4 = endIndex-index+1; |
|
1480 |
||
1481 |
memset4(dst, anObject, n4); |
|
1482 |
} |
|
554 | 1483 |
#else |
2865 | 1484 |
# ifdef FAST_MEMSET |
554 | 1485 |
if ((INT)anObject == 0) { |
1486 |
memset(dst, 0, __OBJS2BYTES__(endIndex-index+1)); |
|
14632 | 1487 |
} else |
2865 | 1488 |
# endif |
1489 |
{ |
|
8919 | 1490 |
# ifdef __UNROLL_LOOPS__ |
554 | 1491 |
{ |
14687 | 1492 |
INT i8; |
554 | 1493 |
|
1494 |
while ((i8 = index + 8) <= endIndex) { |
|
3041 | 1495 |
dst[3] = dst[2] = dst[1] = dst[0] = anObject; |
1496 |
dst[7] = dst[6] = dst[5] = dst[4] = anObject; |
|
554 | 1497 |
dst += 8; |
1498 |
index = i8; |
|
1499 |
} |
|
1500 |
} |
|
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1501 |
# endif |
554 | 1502 |
for (; index <= endIndex; index++) { |
1503 |
*dst++ = anObject; |
|
1504 |
} |
|
1505 |
} |
|
1506 |
#endif |
|
3730
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1507 |
__STORE(self, anObject); |
554 | 1508 |
RETURN ( self ); |
1509 |
} |
|
1510 |
} |
|
1511 |
} |
|
945
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1512 |
%}. |
554 | 1513 |
^ super from:index1 to:index2 put:anObject |
1514 |
! |
|
1515 |
||
543 | 1516 |
replaceFrom:start to:stop with:aCollection startingAt:repStart |
1168 | 1517 |
"replace elements in the receiver between index start and stop, |
1518 |
with elements taken from replacementCollection starting at repStart. |
|
3234 | 1519 |
Return the receiver. |
1168 | 1520 |
Reimplemented for speed if both receiver and aCollection are Arrays" |
543 | 1521 |
|
1522 |
%{ /* NOCONTEXT */ |
|
1523 |
||
14687 | 1524 |
unsigned INT nIndex; |
1525 |
unsigned INT repNIndex; |
|
1526 |
INT startIndex, stopIndex; |
|
543 | 1527 |
REGISTER OBJ *src; |
1528 |
REGISTER OBJ *dst; |
|
14687 | 1529 |
INT repStopIndex; |
1530 |
REGISTER INT repStartIndex; |
|
543 | 1531 |
REGISTER OBJ t; |
14687 | 1532 |
REGISTER INT count; |
1903 | 1533 |
OBJ myClass; |
14632 | 1534 |
|
2210 | 1535 |
if ( |
8913 | 1536 |
(__ClassInstPtr((myClass = __qClass(self)))->c_ninstvars == __mkSmallInteger(0)) |
1903 | 1537 |
&& __isNonNilObject(aCollection) |
1538 |
&& (((t = __qClass(aCollection)) == Array) || (t == myClass)) |
|
543 | 1539 |
&& __bothSmallInteger(start, stop) |
2210 | 1540 |
&& __isSmallInteger(repStart) |
1541 |
) { |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1542 |
startIndex = __intVal(start) - 1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1543 |
if (startIndex >= 0) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1544 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1545 |
stopIndex = __intVal(stop) - 1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1546 |
count = stopIndex - startIndex + 1; |
1903 | 1547 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1548 |
if ((count > 0) && (stopIndex < nIndex)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1549 |
repStartIndex = __intVal(repStart) - 1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1550 |
if (repStartIndex >= 0) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1551 |
repNIndex = __BYTES2OBJS__(__qSize(aCollection)-OHDR_SIZE); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1552 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1553 |
if (repStopIndex < repNIndex) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1554 |
src = &(__InstPtr(aCollection)->i_instvars[repStartIndex]); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1555 |
dst = &(__InstPtr(self)->i_instvars[startIndex]); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1556 |
if (aCollection == self) { |
14632 | 1557 |
/* |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1558 |
* no need to check stores if copying |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1559 |
* from myself |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1560 |
*/ |
1903 | 1561 |
|
14632 | 1562 |
/* |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1563 |
* take care of overlapping copy |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1564 |
* do not depend on memset being smart enough |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1565 |
* (some are not ;-) |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1566 |
*/ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1567 |
if (src < dst) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1568 |
/* must do a reverse copy */ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1569 |
src += count; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1570 |
dst += count; |
8919 | 1571 |
#ifdef __UNROLL_LOOPS__ |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1572 |
while (count > 8) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1573 |
dst[-1] = src[-1]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1574 |
dst[-2] = src[-2]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1575 |
dst[-3] = src[-3]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1576 |
dst[-4] = src[-4]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1577 |
dst[-5] = src[-5]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1578 |
dst[-6] = src[-6]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1579 |
dst[-7] = src[-7]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1580 |
dst[-8] = src[-8]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1581 |
dst -= 8; src -= 8; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1582 |
count -= 8; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1583 |
} |
543 | 1584 |
#endif |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1585 |
while (count-- > 0) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1586 |
*--dst = *--src; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1587 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1588 |
RETURN ( self ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1589 |
} |
1903 | 1590 |
#ifdef SOFTWARE_PIPELINE |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1591 |
{ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1592 |
OBJ t1; |
1903 | 1593 |
|
14632 | 1594 |
/* |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1595 |
* the loop below fetches one longWord behind |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1596 |
* this should not be a problem |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1597 |
*/ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1598 |
t1 = src[0]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1599 |
count--; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1600 |
if (count) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1601 |
dst++; src++; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1602 |
do { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1603 |
dst[-1] = t1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1604 |
t1 = src[0]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1605 |
src++; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1606 |
dst++; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1607 |
} while (count--); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1608 |
} else { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1609 |
dst[0] = t1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1610 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1611 |
} |
543 | 1612 |
#else |
1903 | 1613 |
|
1614 |
# ifdef bcopy4 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1615 |
bcopy4(src, dst, count); |
1903 | 1616 |
# else |
1617 |
# ifdef FAST_MEMCPY |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1618 |
bcopy(src, dst, __OBJS2BYTES__(count)); |
1903 | 1619 |
# else |
8919 | 1620 |
# ifdef __UNROLL_LOOPS__ |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1621 |
while (count >= 8) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1622 |
dst[0] = src[0]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1623 |
dst[1] = src[1]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1624 |
dst[2] = src[2]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1625 |
dst[3] = src[3]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1626 |
dst[4] = src[4]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1627 |
dst[5] = src[5]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1628 |
dst[6] = src[6]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1629 |
dst[7] = src[7]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1630 |
dst += 8; src += 8; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1631 |
count -= 8; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1632 |
} |
1903 | 1633 |
# endif |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1634 |
while (count--) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1635 |
*dst++ = *src++; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1636 |
} |
1903 | 1637 |
# endif |
543 | 1638 |
# endif |
1639 |
#endif |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1640 |
} else { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1641 |
REGISTER int spc; |
543 | 1642 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1643 |
spc = __qSpace(self); |
8919 | 1644 |
#ifdef __UNROLL_LOOPS__ |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1645 |
while (count >= 8) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1646 |
t = src[0]; dst[0] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1647 |
t = src[1]; dst[1] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1648 |
t = src[2]; dst[2] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1649 |
t = src[3]; dst[3] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1650 |
t = src[4]; dst[4] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1651 |
t = src[5]; dst[5] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1652 |
t = src[6]; dst[6] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1653 |
t = src[7]; dst[7] = t; __STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1654 |
count -= 8; src += 8; dst += 8; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1655 |
} |
543 | 1656 |
#endif |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1657 |
while (count-- > 0) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1658 |
t = *src++; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1659 |
*dst++ = t; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1660 |
__STORE_SPC(self, t, spc); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1661 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1662 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1663 |
RETURN ( self ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1664 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1665 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1666 |
} |
1903 | 1667 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1668 |
if (count == 0) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1669 |
RETURN ( self ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1670 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4130
diff
changeset
|
1671 |
} |
543 | 1672 |
} |
1673 |
%}. |
|
1674 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
1168 | 1675 |
|
1676 |
"Modified: 13.4.1996 / 12:17:13 / cg" |
|
543 | 1677 |
! ! |
1678 |
||
1679 |
!Array methodsFor:'printing & storing'! |
|
1680 |
||
13077
87f8b675848f
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12477
diff
changeset
|
1681 |
displayStringName |
87f8b675848f
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12477
diff
changeset
|
1682 |
self class == Array ifTrue:[ |
14632 | 1683 |
^ '#' |
543 | 1684 |
]. |
13077
87f8b675848f
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
12477
diff
changeset
|
1685 |
^ super displayStringName. |
543 | 1686 |
! |
1687 |
||
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1688 |
printOn:aStream |
12162
32aa3e64c889
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
11797
diff
changeset
|
1689 |
"append a printed representation of the receiver to aStream" |
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1690 |
|
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1691 |
self isLiteral ifTrue:[ |
14632 | 1692 |
|limit firstOne s| |
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1693 |
|
14632 | 1694 |
thisContext isRecursive ifTrue:[ |
1695 |
'Array [error]: printOn: of self referencing collection.' errorPrintCR. |
|
1696 |
aStream nextPutAll:'#("recursive")'. |
|
1697 |
^ self |
|
1698 |
]. |
|
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1699 |
|
14632 | 1700 |
aStream nextPutAll:'#('. |
1701 |
firstOne := true. |
|
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1702 |
|
14632 | 1703 |
" |
1704 |
if aStream is not positionable, create an temporary positionable stream |
|
1705 |
(needed for limit calculation) |
|
1706 |
" |
|
1707 |
aStream isPositionable ifTrue:[ |
|
1708 |
s := aStream. |
|
1709 |
] ifFalse:[ |
|
1710 |
s := WriteStream on:(String uninitializedNew:50). |
|
1711 |
]. |
|
1712 |
limit := s position1Based + self maxPrint. |
|
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1713 |
|
14632 | 1714 |
self printElementsDo:[:element | |
1715 |
firstOne ifFalse:[ |
|
1716 |
s space |
|
1717 |
] ifTrue:[ |
|
1718 |
firstOne := false |
|
1719 |
]. |
|
1720 |
(s position1Based >= limit) ifTrue:[ |
|
1721 |
s ~~ aStream ifTrue:[ |
|
1722 |
aStream nextPutAll:(s contents). |
|
1723 |
]. |
|
1724 |
aStream nextPutAll:'...etc...)'. |
|
1725 |
^ self |
|
1726 |
] ifFalse:[ |
|
1727 |
element printOn:s. |
|
1728 |
]. |
|
1729 |
]. |
|
1730 |
s ~~ aStream ifTrue:[ |
|
1731 |
aStream nextPutAll:(s contents). |
|
1732 |
]. |
|
1733 |
aStream nextPut:$) |
|
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1734 |
] ifFalse:[ |
14632 | 1735 |
super printOn:aStream |
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1736 |
] |
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1737 |
|
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1738 |
" |
14632 | 1739 |
#(1 2 $a 'hello' sym kewordSymbol:with: #'funny symbol') printString |
1740 |
#(1 2 $a [1 2 3] true false nil #true #false #nil) printString |
|
8442
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1741 |
" |
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1742 |
|
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1743 |
"Created: 20.11.1995 / 11:16:58 / cg" |
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1744 |
! |
5b4f72d5e966
#printOn: prints Array as #(....) instead of Array(....)
Stefan Vogel <sv@exept.de>
parents:
8368
diff
changeset
|
1745 |
|
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
6497
diff
changeset
|
1746 |
storeArrayElementOn:aStream |
8368 | 1747 |
"Store as element of an array. Omit the leading '#'" |
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
6497
diff
changeset
|
1748 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
6497
diff
changeset
|
1749 |
self isLiteral ifTrue:[ |
14632 | 1750 |
aStream nextPut:$(. |
1751 |
self |
|
1752 |
do:[:element | element storeArrayElementOn:aStream] |
|
1753 |
separatedBy:[aStream space]. |
|
1754 |
aStream nextPut:$). |
|
1755 |
^ self. |
|
8368 | 1756 |
]. |
1757 |
super storeArrayElementOn:aStream |
|
1758 |
||
1759 |
" |
|
14632 | 1760 |
#(1 2 3 4 5) storeOn:Transcript |
1761 |
#(1 2 3 4 5) storeArrayElementOn:Transcript |
|
8368 | 1762 |
" |
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
6497
diff
changeset
|
1763 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
6497
diff
changeset
|
1764 |
|
543 | 1765 |
storeOn:aStream |
1766 |
"append a printed representation of the receiver to aStream, |
|
1767 |
which allows reconstructing it via readFrom:. |
|
1768 |
Redefined to output a somewhat more user friendly string." |
|
1769 |
||
1770 |
self isLiteral ifTrue:[ |
|
14632 | 1771 |
aStream nextPutAll:'#('. |
1772 |
self do:[:element | element storeArrayElementOn:aStream] |
|
1773 |
separatedBy:[aStream space]. |
|
1774 |
aStream nextPut:$) |
|
543 | 1775 |
] ifFalse:[ |
14632 | 1776 |
super storeOn:aStream |
543 | 1777 |
] |
1778 |
||
1779 |
" |
|
14632 | 1780 |
#(1 2 $a 'hello' sym kewordSymbol:with: #'funny symbol') storeString |
1781 |
#(1 2 $a [1 2 3] true false nil #true #false #nil) storeString |
|
543 | 1782 |
" |
588 | 1783 |
|
1784 |
"Created: 20.11.1995 / 11:16:58 / cg" |
|
543 | 1785 |
! ! |
1786 |
||
1787 |
!Array methodsFor:'queries'! |
|
1788 |
||
5557 | 1789 |
basicSize |
1790 |
"return the number of indexed elements in the receiver" |
|
1791 |
||
1792 |
%{ /* NOCONTEXT */ |
|
1793 |
REGISTER OBJ slf = self; |
|
1794 |
||
8913 | 1795 |
RETURN ( __mkSmallInteger(__arraySize(slf) - __intVal(__ClassInstPtr(__qClass(slf))->c_ninstvars) )); |
5557 | 1796 |
%} |
1797 |
! |
|
1798 |
||
1243 | 1799 |
refersToLiteral:aLiteral |
1800 |
"return true if the receiver or recursively any array element in the |
|
5537 | 1801 |
receiver referes to aLiteral (i.e. a deep search)" |
1243 | 1802 |
|
14632 | 1803 |
self do: [ :el | |
6497 | 1804 |
el == aLiteral ifTrue:[^true]. |
1805 |
el class == Array ifTrue:[ |
|
1806 |
(el refersToLiteral: aLiteral) ifTrue: [^true] |
|
1807 |
] |
|
543 | 1808 |
]. |
1809 |
^ false |
|
1810 |
||
1811 |
" |
|
14632 | 1812 |
#(1 2 3) refersToLiteral:#foo |
1813 |
#(1 2 3 foo bar baz) refersToLiteral:#foo |
|
1814 |
#(1 2 3 (((bar foo))) bar baz) refersToLiteral:#foo |
|
543 | 1815 |
" |
1243 | 1816 |
|
5537 | 1817 |
"Modified: / 18.8.2000 / 21:18:14 / cg" |
5557 | 1818 |
! |
1819 |
||
14256
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1820 |
refersToLiteralMatching:aMatchPattern |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1821 |
"return true if the receiver or recursively any array element in the |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1822 |
receiver is symbolic and matches aMatchPattern (i.e. a deep search)" |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1823 |
|
14632 | 1824 |
self do:[ :el | |
1825 |
(el isSymbol and:[ aMatchPattern match: el]) ifTrue:[^true]. |
|
1826 |
el class == Array ifTrue:[ |
|
1827 |
(el refersToLiteralMatching: aMatchPattern) ifTrue: [^true] |
|
1828 |
] |
|
14256
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1829 |
]. |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1830 |
^ false |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1831 |
|
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1832 |
" |
14632 | 1833 |
#(1 2 3) refersToLiteralMatching:#foo |
1834 |
#(1 2 3 foo bar baz) refersToLiteralMatching:#foo |
|
1835 |
#(1 2 3 (((bar foo))) bar baz) refersToLiteralMatching:#foo |
|
14256
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1836 |
" |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1837 |
|
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1838 |
"Modified: / 18-08-2000 / 21:18:14 / cg" |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1839 |
"Created: / 26-07-2012 / 15:38:01 / cg" |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1840 |
! |
45d30f2f4724
added: #refersToLiteralMatching:
Claus Gittinger <cg@exept.de>
parents:
14158
diff
changeset
|
1841 |
|
5557 | 1842 |
size |
1843 |
"return the number of indexed elements in the receiver. |
|
1844 |
Reimplemented here to avoid the additional size->basicSize send |
|
1845 |
(which we can do here, since when arriving here, #size is obviously not |
|
1846 |
redefined in a subclass). |
|
1847 |
This method is the same as basicSize." |
|
1848 |
||
1849 |
%{ /* NOCONTEXT */ |
|
1850 |
REGISTER OBJ slf = self; |
|
1851 |
||
8913 | 1852 |
RETURN ( __mkSmallInteger(__arraySize(slf) - __intVal(__ClassInstPtr(__qClass(slf))->c_ninstvars) )); |
5557 | 1853 |
%} |
543 | 1854 |
! ! |
1855 |
||
3088 | 1856 |
!Array methodsFor:'searching'! |
543 | 1857 |
|
14632 | 1858 |
identityIndexOf:anElement or:alternative |
1859 |
"search the array for anElement or alternative; |
|
554 | 1860 |
return the index of anElement if found, or the index of anAlternative, |
1861 |
if not found. If anAlternative is also not found, return 0. |
|
1862 |
This is a special interface for high-speed searching in an array |
|
1863 |
and at the same time searching for an empty slot. |
|
1864 |
Do not use this method for your application classes, since it is |
|
1865 |
not portable (i.e. other smalltalks do not offer this)" |
|
1866 |
||
1867 |
%{ /* NOCONTEXT */ |
|
1868 |
||
8913 | 1869 |
REGISTER INT index; |
554 | 1870 |
REGISTER OBJ o, el1, el2; |
1871 |
REGISTER OBJ *op; |
|
8913 | 1872 |
REGISTER unsigned INT nIndex; |
1873 |
INT altIndex = 0; |
|
14687 | 1874 |
INT nInsts; |
554 | 1875 |
|
1876 |
index = 0; |
|
1133 | 1877 |
nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
554 | 1878 |
index += nInsts; |
1879 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
14632 | 1880 |
el1 = anElement; el2 = alternative; |
1133 | 1881 |
op = & (__InstPtr(self)->i_instvars[index]); |
554 | 1882 |
while (index++ < nIndex) { |
6497 | 1883 |
if ((o = *op++) == el1) { |
8913 | 1884 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
6497 | 1885 |
} |
1886 |
if (o == el2) { |
|
1887 |
if (altIndex == 0) { |
|
1888 |
altIndex = index; |
|
1889 |
} |
|
1890 |
} |
|
554 | 1891 |
} |
8913 | 1892 |
RETURN ( __mkSmallInteger(altIndex) ); |
5403 | 1893 |
%}. |
1894 |
^ super identityIndexOf:anElement or:alternative |
|
554 | 1895 |
|
1896 |
" |
|
1897 |
#(1 2 3 4 5 6 7 8 9) identityIndexOf:3 or:5 |
|
1898 |
#(1 2 0 4 5 6 7 8 9) identityIndexOf:3 or:5 |
|
1899 |
#(1 2 0 4 5 6 7 3 9) identityIndexOf:3 or:5 |
|
14632 | 1900 |
#(1 2 3 4 5 nil 7 3 9) identityIndexOf:3 or:nil |
1901 |
#(1 2 nil 4 5 6 7 3 9) identityIndexOf:3 or:nil |
|
1902 |
#(1 2 nil 4 5 6 7 8 9) identityIndexOf:3 or:nil |
|
1903 |
#() identityIndexOf:3 or:nil |
|
1904 |
#(1 2) identityIndexOf:3 or:nil |
|
554 | 1905 |
" |
1906 |
! |
|
1907 |
||
543 | 1908 |
identityIndexOf:anElement startingAt:start |
1909 |
"search the array for anElement; return index if found, 0 otherwise |
|
1910 |
- reimplemented for speed" |
|
1911 |
||
1912 |
%{ /* NOCONTEXT */ |
|
1913 |
||
8913 | 1914 |
REGISTER INT index; |
543 | 1915 |
REGISTER OBJ el; |
1916 |
REGISTER OBJ *op; |
|
8913 | 1917 |
REGISTER unsigned INT nIndex; |
14687 | 1918 |
INT nInsts; |
543 | 1919 |
|
1920 |
if (__isSmallInteger(start)) { |
|
6497 | 1921 |
index = __intVal(start) - 1; |
1922 |
if (index >= 0) { |
|
1923 |
nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
1924 |
index += nInsts; |
|
1925 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1926 |
el = anElement; |
|
1927 |
op = & (__InstPtr(self)->i_instvars[index]); |
|
1903 | 1928 |
|
2213 | 1929 |
#if defined(memsrch4) |
6497 | 1930 |
if (index < nIndex) { |
1931 |
OBJ *p; |
|
2213 | 1932 |
|
6497 | 1933 |
p = memsrch4(op, (INT)el, (nIndex - index)); |
1934 |
if (p) { |
|
1935 |
index += (p - op + 1); |
|
14632 | 1936 |
RETURN ( __mkSmallInteger(index) ); |
6497 | 1937 |
} |
1938 |
} |
|
2213 | 1939 |
#else |
2216 | 1940 |
|
8919 | 1941 |
# ifdef __UNROLL_LOOPS__ |
6497 | 1942 |
{ |
1943 |
/* |
|
1944 |
* dont argue about those gotos below - they speed up that thing by 30%; |
|
1945 |
* its better to exit the loops below with a goto, |
|
1946 |
* since the generated code will then be: |
|
1947 |
* compare |
|
1948 |
* branch-on-equal found |
|
1949 |
* |
|
1950 |
* otherwise (with ret as if-statement), we get: |
|
1951 |
* compare |
|
1952 |
* branch-on-not-equal skipLabel |
|
1953 |
* move-to-ret-register true |
|
1954 |
* goto ret-label |
|
1955 |
* skipLabel |
|
1956 |
* |
|
1957 |
* therefore, WITH the so-much-blamed goto, we only branch |
|
1958 |
* when found; without the goto, we branch always. |
|
1959 |
* Pipelined CPUs do usually not like taken branches. |
|
1960 |
*/ |
|
2216 | 1961 |
|
14687 | 1962 |
unsigned INT i8; |
14632 | 1963 |
|
6497 | 1964 |
while ((i8 = index + 8) < nIndex) { |
1965 |
if (op[0] == el) goto found1; |
|
1966 |
if (op[1] == el) goto found2; |
|
1967 |
if (op[2] == el) goto found3; |
|
1968 |
if (op[3] == el) goto found4; |
|
1969 |
if (op[4] == el) goto found5; |
|
1970 |
if (op[5] == el) goto found6; |
|
1971 |
if (op[6] == el) goto found7; |
|
1972 |
if (op[7] == el) goto found8; |
|
1973 |
index = i8; |
|
1974 |
op += 8; |
|
1975 |
} |
|
1976 |
if (0) { |
|
1977 |
found1: |
|
8913 | 1978 |
RETURN ( __mkSmallInteger(index + 1 - nInsts) ); |
6497 | 1979 |
found2: |
8913 | 1980 |
RETURN ( __mkSmallInteger(index + 2 - nInsts) ); |
6497 | 1981 |
found3: |
8913 | 1982 |
RETURN ( __mkSmallInteger(index + 3 - nInsts) ); |
6497 | 1983 |
found4: |
8913 | 1984 |
RETURN ( __mkSmallInteger(index + 4 - nInsts) ); |
6497 | 1985 |
found5: |
8913 | 1986 |
RETURN ( __mkSmallInteger(index + 5 - nInsts) ); |
6497 | 1987 |
found6: |
8913 | 1988 |
RETURN ( __mkSmallInteger(index + 6 - nInsts) ); |
6497 | 1989 |
found7: |
8913 | 1990 |
RETURN ( __mkSmallInteger(index + 7 - nInsts) ); |
6497 | 1991 |
found8: |
8913 | 1992 |
RETURN ( __mkSmallInteger(index + 8 - nInsts) ); |
6497 | 1993 |
} |
1994 |
} |
|
8919 | 1995 |
# endif /* __UNROLLED_LOOPS__ */ |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1996 |
|
6497 | 1997 |
while (index++ < nIndex) { |
1998 |
if (*op++ == el) goto found0; |
|
1999 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
2000 |
|
6497 | 2001 |
if (0) { |
2002 |
found0: |
|
8913 | 2003 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
6497 | 2004 |
} |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
2005 |
#endif /* no memsrch */ |
6497 | 2006 |
} |
8913 | 2007 |
RETURN ( __mkSmallInteger(0) ); |
543 | 2008 |
} |
2009 |
%}. |
|
5403 | 2010 |
^ super identityIndexOf:anElement startingAt:start |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2011 |
! |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2012 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2013 |
identityIndexOf:anElement startingAt:start endingAt:stop |
14632 | 2014 |
"search the array for anElement in the range start..stop; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2015 |
return the index if found, 0 otherwise. |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2016 |
- reimplemented for speed when searching in OrderedCollections" |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2017 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2018 |
%{ /* NOCONTEXT */ |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2019 |
|
8913 | 2020 |
REGISTER INT index; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2021 |
REGISTER OBJ el; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2022 |
REGISTER OBJ *op; |
14687 | 2023 |
REGISTER unsigned INT lastIndex; |
8913 | 2024 |
unsigned INT nIndex; |
14687 | 2025 |
INT nInsts; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2026 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2027 |
if (__bothSmallInteger(start, stop)) { |
6497 | 2028 |
index = __intVal(start) - 1; |
2029 |
if (index >= 0) { |
|
2030 |
nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
2031 |
index += nInsts; |
|
2032 |
lastIndex = nInsts + __intVal(stop); |
|
2033 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
2034 |
if (nIndex < lastIndex) { |
|
2035 |
lastIndex = nIndex; |
|
2036 |
} |
|
2037 |
el = anElement; |
|
2038 |
op = & (__InstPtr(self)->i_instvars[index]); |
|
2213 | 2039 |
|
2040 |
#if defined(memsrch4) |
|
6497 | 2041 |
if (index < lastIndex) { |
2042 |
OBJ *p; |
|
2216 | 2043 |
|
6497 | 2044 |
p = memsrch4(op, (INT)el, (lastIndex - index)); |
2045 |
if (p) { |
|
2046 |
index += (p - op + 1); |
|
14632 | 2047 |
RETURN ( __mkSmallInteger(index) ); |
6497 | 2048 |
} |
2049 |
} |
|
2216 | 2050 |
#else |
2213 | 2051 |
|
8919 | 2052 |
# ifdef __UNROLL_LOOPS__ |
6497 | 2053 |
{ |
14687 | 2054 |
unsigned INT i8; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2055 |
|
6497 | 2056 |
while ((i8 = index + 8) < lastIndex) { |
2057 |
if (op[0] == el) goto found1; |
|
2058 |
if (op[1] == el) goto found2; |
|
2059 |
if (op[2] == el) goto found3; |
|
2060 |
if (op[3] == el) goto found4; |
|
2061 |
if (op[4] == el) goto found5; |
|
2062 |
if (op[5] == el) goto found6; |
|
2063 |
if (op[6] == el) goto found7; |
|
2064 |
if (op[7] == el) goto found8; |
|
2065 |
index = i8; |
|
2066 |
op += 8; |
|
2067 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
2068 |
|
6497 | 2069 |
if (0) { |
2070 |
found1: |
|
8913 | 2071 |
RETURN ( __mkSmallInteger(index + 1 - nInsts) ); |
6497 | 2072 |
found2: |
8913 | 2073 |
RETURN ( __mkSmallInteger(index + 2 - nInsts) ); |
6497 | 2074 |
found3: |
8913 | 2075 |
RETURN ( __mkSmallInteger(index + 3 - nInsts) ); |
6497 | 2076 |
found4: |
8913 | 2077 |
RETURN ( __mkSmallInteger(index + 4 - nInsts) ); |
6497 | 2078 |
found5: |
8913 | 2079 |
RETURN ( __mkSmallInteger(index + 5 - nInsts) ); |
6497 | 2080 |
found6: |
8913 | 2081 |
RETURN ( __mkSmallInteger(index + 6 - nInsts) ); |
6497 | 2082 |
found7: |
8913 | 2083 |
RETURN ( __mkSmallInteger(index + 7 - nInsts) ); |
6497 | 2084 |
found8: |
8913 | 2085 |
RETURN ( __mkSmallInteger(index + 8 - nInsts) ); |
6497 | 2086 |
} |
2087 |
} |
|
8919 | 2088 |
# endif /* __UNROLL_LOOPS__ */ |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
2089 |
|
6497 | 2090 |
while (index++ < lastIndex) { |
2091 |
if (*op++ == el) goto found0; |
|
2092 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
2093 |
|
6497 | 2094 |
if (0) { |
2095 |
found0: |
|
8913 | 2096 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
6497 | 2097 |
} |
2213 | 2098 |
#endif |
6497 | 2099 |
} |
8913 | 2100 |
RETURN ( __mkSmallInteger(0) ); |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2101 |
} |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2102 |
%}. |
5403 | 2103 |
^ super identityIndexOf:anElement startingAt:start endingAt:stop |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2104 |
|
543 | 2105 |
! |
2106 |
||
554 | 2107 |
indexOf:anElement startingAt:start |
2108 |
"search the array for anElement; return index if found, 0 otherwise |
|
2109 |
- reimplemented for speed" |
|
543 | 2110 |
|
554 | 2111 |
|element| |
2112 |
%{ |
|
8913 | 2113 |
REGISTER INT index; |
2114 |
unsigned INT nIndex; |
|
14687 | 2115 |
unsigned INT nInsts; |
554 | 2116 |
static struct inlineCache eq = _ILC1; |
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2117 |
OBJ myClass, e; |
543 | 2118 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
2119 |
myClass = __qClass(self); |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
2120 |
if ( __isSmallInteger(start) ) { |
14632 | 2121 |
index = __intVal(start) - 1; |
2122 |
if (index >= 0) { |
|
2123 |
nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
2124 |
index += nInsts; |
|
2125 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2126 |
|
14632 | 2127 |
e = anElement; |
2128 |
if (e != nil) { |
|
2129 |
/* |
|
2130 |
* special kludge to search for a string; |
|
2131 |
* this is so common, that its worth a special case |
|
2132 |
*/ |
|
825
f7b73d83b9d4
optimized search for strings (dont know if its worth it ...)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
2133 |
#define SPECIAL_STRING_OPT |
f7b73d83b9d4
optimized search for strings (dont know if its worth it ...)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
2134 |
#ifdef SPECIAL_STRING_OPT |
14632 | 2135 |
if (__isStringLike(e)) { |
2136 |
while (index < nIndex) { |
|
2137 |
element = __InstPtr(self)->i_instvars[index++]; |
|
2138 |
if (__isNonNilObject(element)) { |
|
2139 |
if (element == e) { |
|
2140 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2141 |
} |
|
2142 |
if (__qClass(element) == @global(String)) { |
|
2143 |
if (strcmp(__stringVal(e), __stringVal(element)) == 0) { |
|
2144 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2145 |
} |
|
2146 |
} else { |
|
2147 |
if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) { |
|
2148 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2149 |
} |
|
2150 |
/* |
|
2151 |
* send of #= could have lead to a GC - refetch e |
|
2152 |
*/ |
|
2153 |
e = anElement; |
|
2154 |
} |
|
2155 |
} |
|
2156 |
} |
|
2157 |
RETURN (__mkSmallInteger(0)); |
|
2158 |
} |
|
825
f7b73d83b9d4
optimized search for strings (dont know if its worth it ...)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
2159 |
#endif |
14380
06aa294b80fa
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14256
diff
changeset
|
2160 |
#ifdef MAKES_IT_SLOWER_BUT_WHY |
14632 | 2161 |
if (__isSmallInteger(e)) { |
2162 |
/* search for a small number */ |
|
2163 |
while (index < nIndex) { |
|
2164 |
element = __InstPtr(self)->i_instvars[index++]; |
|
2165 |
if (element == e) { |
|
2166 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2167 |
} |
|
2168 |
if (!__isSmallInteger(element)) { |
|
2169 |
if (element != nil) { |
|
2170 |
if ((*eq.ilc_func)(e, |
|
2171 |
@symbol(=), |
|
2172 |
nil,&eq, |
|
2173 |
element) == true) { |
|
2174 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2175 |
} |
|
2176 |
/* |
|
2177 |
* send of #= could have lead to a GC - refetch e |
|
2178 |
*/ |
|
2179 |
e = anElement; |
|
2180 |
} |
|
2181 |
} |
|
2182 |
} |
|
2183 |
RETURN (__mkSmallInteger(0)); |
|
2184 |
} |
|
14380
06aa294b80fa
changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents:
14256
diff
changeset
|
2185 |
#endif /* MAKES_IT_SLOWER_BUT_WHY */ |
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2186 |
|
14632 | 2187 |
while (index < nIndex) { |
2188 |
element = __InstPtr(self)->i_instvars[index++]; |
|
2189 |
if (element != nil) { |
|
2190 |
if ((element == e) |
|
2191 |
|| ((*eq.ilc_func)(e, |
|
2192 |
@symbol(=), |
|
2193 |
nil,&eq, |
|
2194 |
element) == true)) { |
|
2195 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2196 |
} |
|
2197 |
/* |
|
2198 |
* send of #= could have lead to a GC - refetch e |
|
2199 |
*/ |
|
2200 |
e = anElement; |
|
2201 |
} |
|
2202 |
} |
|
2203 |
} else { |
|
2204 |
OBJ slf = self; |
|
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2205 |
|
14632 | 2206 |
/* |
2207 |
* search for nil - do an identity-search |
|
2208 |
*/ |
|
8919 | 2209 |
#ifdef __UNROLL_LOOPS__ |
14632 | 2210 |
{ |
14687 | 2211 |
unsigned INT i8; |
554 | 2212 |
|
14632 | 2213 |
while ((i8 = index + 8) < nIndex) { |
2214 |
if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 1) ); } |
|
2215 |
if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 2) ); } |
|
2216 |
if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 3) ); } |
|
2217 |
if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 4) ); } |
|
2218 |
if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 5) ); } |
|
2219 |
if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 6) ); } |
|
2220 |
if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 7) ); } |
|
2221 |
if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 8) ); } |
|
2222 |
index = i8; |
|
2223 |
} |
|
2224 |
} |
|
554 | 2225 |
#endif |
2226 |
||
14632 | 2227 |
while (index < nIndex) { |
2228 |
if (__InstPtr(slf)->i_instvars[index++] == nil) { |
|
2229 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2230 |
} |
|
2231 |
} |
|
2232 |
} |
|
2233 |
} |
|
2234 |
RETURN (__mkSmallInteger(0)); |
|
543 | 2235 |
} |
554 | 2236 |
%}. |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
2237 |
^ super indexOf:anElement startingAt:start |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2238 |
! |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2239 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2240 |
indexOf:anElement startingAt:start endingAt:stop |
14632 | 2241 |
"search the array for anElement in the range start..stop; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2242 |
Return the index if found, 0 otherwise. |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2243 |
- reimplemented for speed when searching in OrderedCollections" |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2244 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2245 |
|element| |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2246 |
%{ |
8913 | 2247 |
REGISTER INT index; |
2248 |
unsigned INT lastIndex, nIndex; |
|
14687 | 2249 |
unsigned INT nInsts; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2250 |
static struct inlineCache eq = _ILC1; |
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2251 |
OBJ myClass, e; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2252 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
2253 |
myClass = __qClass(self); |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
2254 |
if ( __bothSmallInteger(start, stop) ) { |
14632 | 2255 |
index = __intVal(start) - 1; |
2256 |
if (index >= 0) { |
|
2257 |
nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
2258 |
index += nInsts; |
|
2259 |
lastIndex = nInsts + __intVal(stop); |
|
2260 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
2261 |
if (nIndex < lastIndex) { |
|
2262 |
lastIndex = nIndex; |
|
2263 |
} |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2264 |
|
14632 | 2265 |
e = anElement; |
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2266 |
|
14632 | 2267 |
if (e != nil) { |
2268 |
/* |
|
2269 |
* special kludge to search for a string; |
|
2270 |
* this is so common, that its worth a special case |
|
2271 |
*/ |
|
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2272 |
#define SPECIAL_STRING_OPT |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2273 |
#ifdef SPECIAL_STRING_OPT |
14632 | 2274 |
if (__isStringLike(e)) { |
2275 |
while (index < lastIndex) { |
|
2276 |
element = __InstPtr(self)->i_instvars[index++]; |
|
2277 |
if (__isNonNilObject(element)) { |
|
2278 |
if (element == e) { |
|
2279 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2280 |
} |
|
2281 |
if (__qClass(element) == @global(String)) { |
|
2282 |
if (strcmp(__stringVal(e), __stringVal(element)) == 0) { |
|
2283 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2284 |
} |
|
2285 |
} else { |
|
2286 |
if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) { |
|
2287 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2288 |
} |
|
2289 |
/* |
|
2290 |
* send of #= could have lead to a GC - refetch e |
|
2291 |
*/ |
|
2292 |
e = anElement; |
|
2293 |
} |
|
2294 |
} |
|
2295 |
} |
|
2296 |
RETURN (__mkSmallInteger(0)); |
|
2297 |
} |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2298 |
#endif |
14632 | 2299 |
if (__isSmallInteger(e)) { |
2300 |
/* search for a small number */ |
|
2301 |
while (index < lastIndex) { |
|
2302 |
element = __InstPtr(self)->i_instvars[index++]; |
|
2303 |
if (element == e) { |
|
2304 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2305 |
} |
|
2306 |
if (!__isSmallInteger(element)) { |
|
2307 |
if ((*eq.ilc_func)(e, |
|
2308 |
@symbol(=), |
|
2309 |
nil,&eq, |
|
2310 |
element) == true) { |
|
2311 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2312 |
} |
|
2313 |
/* |
|
2314 |
* send of #= could have lead to a GC - refetch e |
|
2315 |
*/ |
|
2316 |
e = anElement; |
|
2317 |
} |
|
2318 |
} |
|
2319 |
RETURN (__mkSmallInteger(0)); |
|
2320 |
} |
|
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2321 |
|
14632 | 2322 |
while (index < lastIndex) { |
2323 |
element = __InstPtr(self)->i_instvars[index++]; |
|
2324 |
if (element != nil) { |
|
2325 |
e = anElement; |
|
2326 |
if ((element == e) |
|
2327 |
|| ((*eq.ilc_func)(e, |
|
2328 |
@symbol(=), |
|
2329 |
nil,&eq, |
|
2330 |
element) == true)) { |
|
2331 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2332 |
} |
|
2333 |
} |
|
2334 |
} |
|
2335 |
} else { |
|
2336 |
OBJ slf = self; |
|
4130
662554f2a37c
avoid refetch of void variables (if possible)
Claus Gittinger <cg@exept.de>
parents:
4122
diff
changeset
|
2337 |
|
14632 | 2338 |
/* |
2339 |
* search for nil - do an identity-search |
|
2340 |
*/ |
|
8919 | 2341 |
#ifdef __UNROLL_LOOPS__ |
14632 | 2342 |
{ |
14687 | 2343 |
unsigned INT i8; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2344 |
|
14632 | 2345 |
while ((i8 = index + 8) < lastIndex) { |
2346 |
if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 1) ); } |
|
2347 |
if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 2) ); } |
|
2348 |
if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 3) ); } |
|
2349 |
if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 4) ); } |
|
2350 |
if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 5) ); } |
|
2351 |
if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 6) ); } |
|
2352 |
if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 7) ); } |
|
2353 |
if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 8) ); } |
|
2354 |
index = i8; |
|
2355 |
} |
|
2356 |
} |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2357 |
#endif |
14632 | 2358 |
while (index < lastIndex) { |
2359 |
if (__InstPtr(slf)->i_instvars[index++] == nil) { |
|
2360 |
RETURN ( __mkSmallInteger(index - nInsts) ); |
|
2361 |
} |
|
2362 |
} |
|
2363 |
} |
|
2364 |
} |
|
2365 |
RETURN (__mkSmallInteger(0)); |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2366 |
} |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2367 |
%}. |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2368 |
^ super indexOf:anElement startingAt:start endingAt:stop |
1 | 2369 |
! ! |
543 | 2370 |
|
3088 | 2371 |
!Array methodsFor:'testing'! |
2372 |
||
2373 |
includes:anObject |
|
2374 |
"return true, if the argument, anObject is contained in the array |
|
2375 |
- reimplemented for speed" |
|
2376 |
||
2377 |
|element| |
|
2378 |
||
2379 |
%{ /* NOCONTEXT */ |
|
14632 | 2380 |
/* |
3088 | 2381 |
* first, do a quick check using == |
2382 |
* this does not need a context or message send. |
|
2383 |
* In many cases this will already find a match. |
|
2384 |
*/ |
|
14687 | 2385 |
REGISTER INT index; |
3088 | 2386 |
REGISTER OBJ o; |
14687 | 2387 |
unsigned INT nIndex; |
3088 | 2388 |
|
2389 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
2390 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
2391 |
||
4309 | 2392 |
o = anObject; |
2393 |
||
3088 | 2394 |
/* |
2395 |
* however, the search is limited to the first 500 |
|
2396 |
* elements, since otherwise, we may spend too much time |
|
2397 |
* searching for identity if an equal value is found early |
|
2398 |
* (except if searching for nil - there is no need for equal compare ...) |
|
2399 |
*/ |
|
2400 |
if (nIndex > 500) { |
|
6497 | 2401 |
if (o != nil) |
2402 |
nIndex = 500; |
|
3088 | 2403 |
} |
2404 |
||
2405 |
# ifdef memsrch4 |
|
2406 |
if (index < nIndex) { |
|
6497 | 2407 |
OBJ *p; |
3088 | 2408 |
|
6497 | 2409 |
p = memsrch4(&(__InstPtr(self)->i_instvars[index]), (INT)o, (nIndex - index)); |
2410 |
if (p) { |
|
2411 |
RETURN ( true ); |
|
2412 |
} |
|
3088 | 2413 |
} |
2414 |
||
2415 |
# else |
|
2416 |
/* |
|
2417 |
* dont argue those gotos below - they speed up that thing by 30% |
|
2418 |
* its better to exit the loops below with a goto, |
|
2419 |
* since the generated code will then be: |
|
2420 |
* compare |
|
2421 |
* branch-on-equal found |
|
2422 |
* |
|
2423 |
* otherwise, we get: |
|
2424 |
* compare |
|
2425 |
* branch-on-not-equal skipLabel |
|
2426 |
* move-to-return-register true |
|
2427 |
* goto return-label |
|
2428 |
* skipLabel |
|
2429 |
* |
|
2430 |
* therefore, WITH the so-much-blamed goto, we only branch |
|
2431 |
* when found; without the goto, we branch always. |
|
2432 |
* Pipelined CPUs do usually not like taken branches. |
|
2433 |
* also, all branches are forward, which are usually predicted |
|
2434 |
* as not taken. |
|
2435 |
*/ |
|
8919 | 2436 |
# ifdef __UNROLL_LOOPS__ |
3088 | 2437 |
{ |
14687 | 2438 |
unsigned INT i8; |
6497 | 2439 |
REGISTER OBJ slf = self; |
3088 | 2440 |
|
6497 | 2441 |
while ((i8 = index + 8) < nIndex) { |
2442 |
if (__InstPtr(slf)->i_instvars[index] == o) goto found; |
|
2443 |
if (__InstPtr(slf)->i_instvars[index+1] == o) goto found; |
|
2444 |
if (__InstPtr(slf)->i_instvars[index+2] == o) goto found; |
|
2445 |
if (__InstPtr(slf)->i_instvars[index+3] == o) goto found; |
|
2446 |
if (__InstPtr(slf)->i_instvars[index+4] == o) goto found; |
|
2447 |
if (__InstPtr(slf)->i_instvars[index+5] == o) goto found; |
|
2448 |
if (__InstPtr(slf)->i_instvars[index+6] == o) goto found; |
|
2449 |
if (__InstPtr(slf)->i_instvars[index+7] == o) goto found; |
|
2450 |
index = i8; |
|
2451 |
} |
|
3088 | 2452 |
} |
8919 | 2453 |
# endif /* __UNROLL_LOOPS__ */ |
3088 | 2454 |
|
2455 |
while (index < nIndex) { |
|
6497 | 2456 |
if (__InstPtr(self)->i_instvars[index++] == o) goto found; |
3088 | 2457 |
} |
2458 |
if (0) { |
|
6497 | 2459 |
found: |
2460 |
RETURN (true); |
|
3088 | 2461 |
} |
2462 |
||
2463 |
# endif /* no memsrch */ |
|
2464 |
||
2465 |
if (o == nil) { |
|
6497 | 2466 |
RETURN ( false ); |
3088 | 2467 |
} |
5403 | 2468 |
%}. |
2469 |
||
2470 |
%{ |
|
14687 | 2471 |
REGISTER INT index; |
5403 | 2472 |
REGISTER OBJ o; |
14687 | 2473 |
unsigned INT nIndex; |
5403 | 2474 |
static struct inlineCache eq = _ILC1; |
3088 | 2475 |
|
14632 | 2476 |
/* |
3088 | 2477 |
* then do a slow(er) check using = |
2478 |
*/ |
|
2479 |
||
14632 | 2480 |
/* |
3088 | 2481 |
* sorry: cannot access the stuff from above ... |
2482 |
*/ |
|
2483 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
2484 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
2485 |
||
2486 |
while (index < nIndex) { |
|
6497 | 2487 |
element = __InstPtr(self)->i_instvars[index++]; |
2488 |
if (element != nil) { |
|
2489 |
if ((*eq.ilc_func)(anObject, |
|
2490 |
@symbol(=), |
|
2491 |
nil,&eq, |
|
2492 |
element)==true) { |
|
2493 |
RETURN ( true ); |
|
2494 |
} |
|
2495 |
} |
|
3088 | 2496 |
} |
5403 | 2497 |
RETURN (false); |
3088 | 2498 |
%}. |
5403 | 2499 |
^ super includes:anObject |
5049 | 2500 |
! |
2501 |
||
2502 |
includesIdentical:anObject |
|
2503 |
"return true, if the argument, anObject is contained in the array |
|
2504 |
uses #== (instead of #=) when comparing; i.e. the search is for |
|
2505 |
the object, not some object being equal." |
|
2506 |
||
2507 |
^ (self identityIndexOf:anObject) ~~ 0 |
|
2508 |
||
2509 |
" |
|
2510 |
#(1 2 3 4 5) includes:3.0 |
|
2511 |
||
2512 |
#(1 2 3 4 5) includesIdentical:3.0 |
|
2513 |
" |
|
5554 | 2514 |
! |
2515 |
||
2516 |
isArray |
|
2517 |
"return true, if the receiver is some kind of array (or weakArray etc). |
|
2518 |
true is returned here." |
|
2519 |
||
2520 |
^ true |
|
2521 |
! |
|
2522 |
||
2523 |
isEmpty |
|
2524 |
"return true if the receiver contains no elements. |
|
2525 |
Reimplemented here for performance." |
|
2526 |
||
2527 |
%{ /* NOCONTEXT */ |
|
2528 |
REGISTER OBJ slf = self; |
|
2529 |
||
2530 |
if (__qClass(slf) == Array) { |
|
2531 |
RETURN ( (__arraySize(slf) == 0) ? true : false); |
|
2532 |
} |
|
2533 |
%}. |
|
2534 |
^ self size == 0 |
|
2535 |
! |
|
2536 |
||
2537 |
isLiteral |
|
2538 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
2539 |
(i.e. can be used in constant arrays)" |
|
2540 |
||
2541 |
"/ no, simply returning true here is a mistake: |
|
14632 | 2542 |
"/ it could be a subclass of Array |
5554 | 2543 |
"/ (of which the compiler does not know at all ...) |
2544 |
||
2545 |
self class == Array ifFalse:[^ false]. |
|
2546 |
||
2547 |
"/ |
|
2548 |
"/ care for recursive arrays ... |
|
2549 |
"/ |
|
2550 |
thisContext isRecursive ifTrue:[^ false]. |
|
10089
833fffc641ef
code cleanup: use #conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9360
diff
changeset
|
2551 |
^ self conform:[:element | element isLiteral]. |
5554 | 2552 |
|
10089
833fffc641ef
code cleanup: use #conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
9360
diff
changeset
|
2553 |
"Modified: / 13-10-2006 / 13:00:45 / cg" |
5554 | 2554 |
! |
2555 |
||
2556 |
notEmpty |
|
2557 |
"return true if the receiver contains elements. |
|
2558 |
Reimplemented here for performance." |
|
2559 |
||
2560 |
%{ /* NOCONTEXT */ |
|
2561 |
REGISTER OBJ slf = self; |
|
2562 |
||
2563 |
if (__qClass(slf) == Array) { |
|
2564 |
RETURN ( (__arraySize(slf) != 0) ? true : false); |
|
2565 |
} |
|
2566 |
%}. |
|
2567 |
^ self size ~~ 0 |
|
3088 | 2568 |
! ! |
2569 |
||
4681 | 2570 |
!Array methodsFor:'tracing'! |
2571 |
||
2572 |
traceInto:aRequestor level:level from:referrer |
|
2573 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
2574 |
||
2575 |
^ aRequestor traceArray:self level:level from:referrer |
|
2576 |
||
2577 |
||
2578 |
! ! |
|
2579 |
||
1903 | 2580 |
!Array class methodsFor:'documentation'! |
626 | 2581 |
|
2582 |
version |
|
15061 | 2583 |
^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.158 2013-04-04 07:55:57 cg Exp $' |
12162
32aa3e64c889
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
11797
diff
changeset
|
2584 |
! |
32aa3e64c889
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
11797
diff
changeset
|
2585 |
|
32aa3e64c889
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
11797
diff
changeset
|
2586 |
version_CVS |
15061 | 2587 |
^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.158 2013-04-04 07:55:57 cg Exp $' |
1244 | 2588 |
! ! |
14995 | 2589 |