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