author | Claus Gittinger <cg@exept.de> |
Wed, 05 Aug 1998 11:24:20 +0200 | |
changeset 3730 | 375237229a8e |
parent 3500 | 90eb689740cc |
child 3979 | 46a2da9b917d |
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; |
3730
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
463 |
__STORE(nObj, Array); |
1 | 464 |
|
155 | 465 |
nIndex = __BYTES2OBJS__(sz - OHDR_SIZE - sizeof(OBJ)); |
370 | 466 |
/* |
467 |
* sorry: |
|
468 |
* cannot use bcopy, since we must take care of stores ... |
|
469 |
* could check for: notRemembered + inOld + notLifoRem |
|
470 |
* + not incrGCRunning |
|
471 |
* but copyWith: is not heavily used by real programmers ... |
|
472 |
*/ |
|
473 |
spc = __qSpace(nObj); |
|
1133 | 474 |
srcP = __ArrayInstPtr(self)->a_element; |
475 |
dstP = __ArrayInstPtr(nObj)->a_element; |
|
1903 | 476 |
|
393 | 477 |
#ifdef UNROLL_LOOPS |
478 |
while (nIndex >= 4) { |
|
479 |
element = srcP[0]; |
|
480 |
dstP[0] = element; |
|
481 |
__STORE_SPC(nObj, element, spc); |
|
482 |
element = srcP[1]; |
|
483 |
dstP[1] = element; |
|
484 |
__STORE_SPC(nObj, element, spc); |
|
485 |
element = srcP[2]; |
|
486 |
dstP[2] = element; |
|
487 |
__STORE_SPC(nObj, element, spc); |
|
488 |
element = srcP[3]; |
|
489 |
dstP[3] = element; |
|
490 |
__STORE_SPC(nObj, element, spc); |
|
491 |
srcP += 4; |
|
492 |
dstP += 4; |
|
493 |
nIndex -= 4; |
|
494 |
} |
|
495 |
#endif |
|
155 | 496 |
while (nIndex--) { |
497 |
element = *srcP++; |
|
498 |
*dstP++ = element; |
|
293 | 499 |
__STORE_SPC(nObj, element, spc); |
155 | 500 |
} |
501 |
*dstP = something; |
|
293 | 502 |
__STORE_SPC(nObj, something, spc); |
155 | 503 |
RETURN ( nObj ); |
504 |
} |
|
1 | 505 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
506 |
%}. |
1 | 507 |
^ super copyWith:something |
508 |
! ! |
|
509 |
||
216 | 510 |
!Array methodsFor:'enumerating'! |
1 | 511 |
|
554 | 512 |
addAllTo:aCollection |
513 |
"add all elements of the receiver to aCollection. |
|
514 |
return aCollection." |
|
515 |
||
516 |
|stop "{ Class: SmallInteger }"| |
|
517 |
||
518 |
stop := self size. |
|
519 |
1 to:stop do:[:idx | |
|
520 |
aCollection add:(self at:idx) |
|
521 |
]. |
|
522 |
^ aCollection |
|
523 |
! |
|
524 |
||
525 |
do:aBlock |
|
526 |
"evaluate the argument, aBlock for each element in the collection. |
|
527 |
- reimplemented for speed" |
|
528 |
||
2202 | 529 |
| 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
|
530 |
|
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
531 |
sz := self size. |
554 | 532 |
%{ |
533 |
REGISTER OBJFUNC codeVal; |
|
534 |
REGISTER int index; |
|
535 |
unsigned int nIndex; |
|
536 |
static struct inlineCache val = _ILC1; |
|
537 |
REGISTER OBJ rHome; |
|
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
538 |
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
|
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 |
{ |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
541 |
OBJ mySelf = self; |
554 | 542 |
|
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
|
543 |
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
|
544 |
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
|
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 |
|
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 |
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
|
548 |
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
|
549 |
|
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
|
550 |
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
|
551 |
&& (__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
|
552 |
{ |
2915 | 553 |
/* |
554 |
* 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
|
555 |
*/ |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
556 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
557 |
|
2915 | 558 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 559 |
#ifdef PARANOIA |
2915 | 560 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 561 |
#endif |
562 |
) { |
|
2254 | 563 |
|
554 | 564 |
#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
|
565 |
# define BLOCK_ARG aBlock |
554 | 566 |
#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
|
567 |
# 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
|
568 |
REGISTER OBJ rHome; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
569 |
|
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
|
570 |
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
|
571 |
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
|
572 |
#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
|
573 |
{ |
2216 | 574 |
|
2878 | 575 |
/* |
576 |
* boy; what an ugly looking piece of code ... |
|
577 |
* however, this software pipelined thing has no taken conditional |
|
578 |
* branches in the normal case and is almost twice as fast to even |
|
579 |
* what an unrolling optimizing compiler produces from the loop below ... |
|
580 |
* notice, that those gotos expand to forward branches (which are predicted |
|
581 |
* as NOT taken by most machines ... which is exactly what we want) |
|
582 |
*/ |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
583 |
REGISTER OBJ el; |
3484 | 584 |
#if defined(UNROLL_LOOPS) |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
585 |
|
2216 | 586 |
{ |
587 |
int i8; |
|
588 |
||
589 |
while ((i8 = index+8) < nIndex) { |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
590 |
el = __InstPtr(self)->i_instvars[index]; |
2216 | 591 |
if (InterruptPending != nil) goto interrupt0; |
592 |
continue0: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
593 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
594 |
el = __InstPtr(self)->i_instvars[index+1]; |
2216 | 595 |
if (InterruptPending != nil) goto interrupt1; |
596 |
continue1: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
597 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
598 |
el = __InstPtr(self)->i_instvars[index+2]; |
2216 | 599 |
if (InterruptPending != nil) goto interrupt2; |
600 |
continue2: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
601 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
602 |
el = __InstPtr(self)->i_instvars[index+3]; |
2216 | 603 |
if (InterruptPending != nil) goto interrupt3; |
604 |
continue3: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
605 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
606 |
el = __InstPtr(self)->i_instvars[index+4]; |
2216 | 607 |
if (InterruptPending != nil) goto interrupt4; |
608 |
continue4: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
609 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
610 |
el = __InstPtr(self)->i_instvars[index+5]; |
2216 | 611 |
if (InterruptPending != nil) goto interrupt5; |
612 |
continue5: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
613 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
614 |
el = __InstPtr(self)->i_instvars[index+6]; |
2216 | 615 |
if (InterruptPending != nil) goto interrupt6; |
616 |
continue6: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
617 |
(*codeVal)(BLOCK_ARG, el); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
618 |
el = __InstPtr(self)->i_instvars[index+7]; |
2216 | 619 |
if (InterruptPending != nil) goto interrupt7; |
620 |
continue7: |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
621 |
(*codeVal)(BLOCK_ARG, el); |
2216 | 622 |
index = i8; |
623 |
} |
|
624 |
} |
|
3484 | 625 |
#endif /* UNROLL_LOOPS */ |
2216 | 626 |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
627 |
for (; index < nIndex; index++) { |
2217 | 628 |
el = __InstPtr(self)->i_instvars[index]; |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
629 |
if (InterruptPending != nil) goto interruptX; |
2915 | 630 |
continueX: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
631 |
(*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
|
632 |
} |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
633 |
RETURN (self); |
2216 | 634 |
|
3484 | 635 |
#if defined(UNROLL_LOOPS) |
2216 | 636 |
interrupt0: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
637 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
638 |
el = __InstPtr(self)->i_instvars[index]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
639 |
goto continue0; |
2216 | 640 |
interrupt1: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
641 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
642 |
el = __InstPtr(self)->i_instvars[index+1]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
643 |
goto continue1; |
2216 | 644 |
interrupt2: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
645 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
646 |
el = __InstPtr(self)->i_instvars[index+2]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
647 |
goto continue2; |
2216 | 648 |
interrupt3: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
649 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
650 |
el = __InstPtr(self)->i_instvars[index+3]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
651 |
goto continue3; |
2216 | 652 |
interrupt4: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
653 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
654 |
el = __InstPtr(self)->i_instvars[index+4]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
655 |
goto continue4; |
2216 | 656 |
interrupt5: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
657 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
658 |
el = __InstPtr(self)->i_instvars[index+5]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
659 |
goto continue5; |
2216 | 660 |
interrupt6: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
661 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
662 |
el = __InstPtr(self)->i_instvars[index+6]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
663 |
goto continue6; |
2216 | 664 |
interrupt7: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
665 |
__interruptL(@line); |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
666 |
el = __InstPtr(self)->i_instvars[index+7]; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
667 |
goto continue7; |
3500 | 668 |
#endif /* UNROLL_LOOPS */ |
2715
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; |
3500 | 673 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
674 |
} |
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
|
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 |
/* |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
678 |
* 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
|
679 |
* 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
|
680 |
*/ |
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 |
# undef BLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
682 |
#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
|
683 |
# 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
|
684 |
# 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
|
685 |
#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
|
686 |
# 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
|
687 |
# 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
|
688 |
#endif |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
689 |
|
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
|
690 |
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
|
691 |
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
|
692 |
|
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 |
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
|
694 |
|
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
|
695 |
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
|
696 |
(*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
|
697 |
} 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
|
698 |
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
|
699 |
/* |
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 |
* 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
|
701 |
* 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
|
702 |
*/ |
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 |
#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
|
704 |
__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
|
705 |
#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
|
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 |
#endif |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
708 |
} 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
|
709 |
(*val.ilc_func)(aBlock, |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
710 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
711 |
nil, &val, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
712 |
__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
|
713 |
} |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
714 |
} |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
715 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
716 |
|
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
|
717 |
# 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
|
718 |
# 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
|
719 |
|
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 |
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
|
721 |
} |
554 | 722 |
|
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
|
723 |
/* |
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
724 |
* 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
|
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 |
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
|
727 |
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
|
728 |
|
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 |
(*val.ilc_func)(aBlock, |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
730 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
731 |
nil, &val, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
732 |
__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
|
733 |
} |
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
|
734 |
RETURN ( self ); |
554 | 735 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
736 |
/* |
2357
061dadc13df1
removed WEAKPOINTER checks - WeakArray is no longer allowed to be a subclass of Array
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
737 |
* 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
|
738 |
*/ |
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
|
739 |
%}. |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
740 |
^ super do:aBlock |
554 | 741 |
! |
742 |
||
1 | 743 |
from:start to:stop do:aBlock |
744 |
"evaluate the argument, aBlock for the elements starting at index start |
|
745 |
up to (and including) stop in the collection. |
|
746 |
- reimplemented for speed" |
|
747 |
||
748 |
%{ |
|
749 |
REGISTER OBJFUNC codeVal; |
|
750 |
REGISTER int index; |
|
2 | 751 |
REGISTER OBJ rHome; |
2052 | 752 |
OBJ slf; |
1 | 753 |
int nIndex, nInsts; |
754 |
static struct inlineCache val = _ILC1; |
|
3484 | 755 |
int indexHigh; |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
756 |
OBJ myClass; |
3484 | 757 |
OBJ __start, __stop; |
1 | 758 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
759 |
slf = self; |
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
760 |
myClass = __qClass(slf); |
3484 | 761 |
|
762 |
__start = start; |
|
763 |
__stop = stop; |
|
764 |
if ( __bothSmallInteger(__start, __stop) |
|
765 |
&& ((index = __intVal(__start)) > 0) ) { |
|
766 |
indexHigh = __intVal(__stop); |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
767 |
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
|
768 |
if (myClass != @global(Array)) { |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
769 |
nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
3484 | 770 |
index += nInsts; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
771 |
indexHigh += nInsts; |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
772 |
} |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
773 |
if (indexHigh <= nIndex) { |
3484 | 774 |
OBJ __aBlock = aBlock; |
775 |
int n; |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
776 |
|
3484 | 777 |
index--; /* 0-based */ |
778 |
n = indexHigh - index; |
|
779 |
||
780 |
if (__isBlockLike(__aBlock) |
|
781 |
&& (__BlockInstPtr(__aBlock)->b_nargs == __MKSMALLINT(1))) { |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
782 |
{ |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
783 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
784 |
* 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
|
785 |
*/ |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
786 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
787 |
|
3484 | 788 |
if (((codeVal = __BlockInstPtr(__aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 789 |
#ifdef PARANOIA |
3484 | 790 |
&& (! ((INT)(__BlockInstPtr(__aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 791 |
#endif |
792 |
) { |
|
11 | 793 |
#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
|
794 |
# define BLOCK_ARG aBlock |
11 | 795 |
#else |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
796 |
# define BLOCK_ARG rHome |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
797 |
REGISTER OBJ rHome; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
798 |
|
3484 | 799 |
rHome = __BlockInstPtr(__aBlock)->b_home; |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
800 |
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
|
801 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
802 |
{ |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
803 |
REGISTER OBJ el; |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
804 |
|
3484 | 805 |
#if defined(UNROLL_LOOPS) |
2216 | 806 |
/* |
807 |
* boy; what an ugly looking piece of code ... |
|
808 |
* however, this software pipelined thing has no taken conditional |
|
809 |
* branches in the normal case and is almost twice as fast to even |
|
810 |
* what an unrolling optimizing compiler produces from the loop below ... |
|
2683 | 811 |
* notice, that those gotos expand to forward branches (which are predicted |
812 |
* as NOT taken by most machines ... which is exactly what we want) |
|
2216 | 813 |
*/ |
814 |
{ |
|
3484 | 815 |
while ( n >= 8) { |
2216 | 816 |
el = __InstPtr(self)->i_instvars[index]; |
817 |
if (InterruptPending != nil) goto interrupt0; |
|
818 |
continue0: |
|
819 |
(*codeVal)(BLOCK_ARG, el); |
|
820 |
el = __InstPtr(self)->i_instvars[index+1]; |
|
821 |
if (InterruptPending != nil) goto interrupt1; |
|
822 |
continue1: |
|
823 |
(*codeVal)(BLOCK_ARG, el); |
|
824 |
el = __InstPtr(self)->i_instvars[index+2]; |
|
825 |
if (InterruptPending != nil) goto interrupt2; |
|
826 |
continue2: |
|
827 |
(*codeVal)(BLOCK_ARG, el); |
|
828 |
el = __InstPtr(self)->i_instvars[index+3]; |
|
829 |
if (InterruptPending != nil) goto interrupt3; |
|
830 |
continue3: |
|
831 |
(*codeVal)(BLOCK_ARG, el); |
|
832 |
el = __InstPtr(self)->i_instvars[index+4]; |
|
833 |
if (InterruptPending != nil) goto interrupt4; |
|
834 |
continue4: |
|
835 |
(*codeVal)(BLOCK_ARG, el); |
|
836 |
el = __InstPtr(self)->i_instvars[index+5]; |
|
837 |
if (InterruptPending != nil) goto interrupt5; |
|
838 |
continue5: |
|
839 |
(*codeVal)(BLOCK_ARG, el); |
|
840 |
el = __InstPtr(self)->i_instvars[index+6]; |
|
841 |
if (InterruptPending != nil) goto interrupt6; |
|
842 |
continue6: |
|
843 |
(*codeVal)(BLOCK_ARG, el); |
|
844 |
el = __InstPtr(self)->i_instvars[index+7]; |
|
845 |
if (InterruptPending != nil) goto interrupt7; |
|
846 |
continue7: |
|
847 |
(*codeVal)(BLOCK_ARG, el); |
|
3484 | 848 |
n -= 8; |
849 |
index += 8; |
|
2216 | 850 |
} |
3485 | 851 |
# ifdef UNROLL_LOOPS2 /* this makes small loops slower */ |
3484 | 852 |
if (n >= 4) { |
853 |
el = __InstPtr(self)->i_instvars[index]; |
|
854 |
if (InterruptPending != nil) goto interrupt0b; |
|
855 |
continue0b: |
|
856 |
(*codeVal)(BLOCK_ARG, el); |
|
857 |
el = __InstPtr(self)->i_instvars[index+1]; |
|
858 |
if (InterruptPending != nil) goto interrupt1b; |
|
859 |
continue1b: |
|
860 |
(*codeVal)(BLOCK_ARG, el); |
|
861 |
el = __InstPtr(self)->i_instvars[index+2]; |
|
862 |
if (InterruptPending != nil) goto interrupt2b; |
|
863 |
continue2b: |
|
864 |
(*codeVal)(BLOCK_ARG, el); |
|
865 |
el = __InstPtr(self)->i_instvars[index+3]; |
|
866 |
if (InterruptPending != nil) goto interrupt3b; |
|
867 |
continue3b: |
|
868 |
(*codeVal)(BLOCK_ARG, el); |
|
869 |
n -= 4; |
|
870 |
index += 4; |
|
871 |
} |
|
872 |
if (n >= 2) { |
|
873 |
el = __InstPtr(self)->i_instvars[index]; |
|
874 |
if (InterruptPending != nil) goto interrupt0c; |
|
875 |
continue0c: |
|
876 |
(*codeVal)(BLOCK_ARG, el); |
|
877 |
el = __InstPtr(self)->i_instvars[index+1]; |
|
878 |
if (InterruptPending != nil) goto interrupt1c; |
|
879 |
continue1c: |
|
880 |
(*codeVal)(BLOCK_ARG, el); |
|
881 |
n -= 2; |
|
882 |
index += 2; |
|
883 |
} |
|
3485 | 884 |
# endif /* UNROLL_LOOPS2 */ |
2216 | 885 |
} |
3500 | 886 |
#endif /* UNROLL_LOOPS */ |
3484 | 887 |
while (n > 0) { |
2217 | 888 |
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
|
889 |
if (InterruptPending != nil) goto interruptX; |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
890 |
continueX: |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
891 |
(*codeVal)(BLOCK_ARG, el); |
3484 | 892 |
n--; |
893 |
index++; |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
894 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
895 |
RETURN (self); |
2216 | 896 |
|
3484 | 897 |
#if defined(UNROLL_LOOPS) |
2216 | 898 |
interrupt0: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
899 |
__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
|
900 |
goto continue0; |
2216 | 901 |
interrupt1: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
902 |
__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
|
903 |
goto continue1; |
2216 | 904 |
interrupt2: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
905 |
__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
|
906 |
goto continue2; |
2216 | 907 |
interrupt3: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
908 |
__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
|
909 |
goto continue3; |
2216 | 910 |
interrupt4: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
911 |
__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
|
912 |
goto continue4; |
2216 | 913 |
interrupt5: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
914 |
__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
|
915 |
goto continue5; |
2216 | 916 |
interrupt6: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
917 |
__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
|
918 |
goto continue6; |
2216 | 919 |
interrupt7: |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
920 |
__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
|
921 |
goto continue7; |
3484 | 922 |
|
3485 | 923 |
# ifdef UNROLL_LOOPS2 |
3484 | 924 |
interrupt0b: |
925 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index]; |
|
926 |
goto continue0b; |
|
927 |
interrupt1b: |
|
928 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+1]; |
|
929 |
goto continue1b; |
|
930 |
interrupt2b: |
|
931 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+2]; |
|
932 |
goto continue2b; |
|
933 |
interrupt3b: |
|
934 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+3]; |
|
935 |
goto continue3b; |
|
936 |
||
937 |
interrupt0c: |
|
938 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index]; |
|
939 |
goto continue0c; |
|
940 |
interrupt1c: |
|
941 |
__interruptL(@line); el = __InstPtr(self)->i_instvars[index+1]; |
|
942 |
goto continue1c; |
|
3485 | 943 |
# endif /* UNROLL_LOOPS2 */ |
944 |
#endif /* UNROLL_LOOPS */ |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
945 |
interruptX: |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
946 |
__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
|
947 |
goto continueX; |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
948 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
949 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
950 |
} |
370 | 951 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
952 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
953 |
* sorry, must check code-pointer in the loop |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
954 |
* it could be recompiled or flushed |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
955 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
956 |
# undef BLOCK_ARG |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
957 |
#ifdef NEW_BLOCK_CALL |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
958 |
# define BLOCK_ARG aBlock |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
959 |
# define IBLOCK_ARG nil |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
960 |
#else |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
961 |
# 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
|
962 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
11 | 963 |
#endif |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
964 |
|
3484 | 965 |
while (n) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
966 |
REGISTER OBJFUNC codeVal; |
3484 | 967 |
OBJ el; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
968 |
|
3484 | 969 |
el = __InstPtr(self)->i_instvars[index]; |
970 |
if (InterruptPending != nil) { |
|
971 |
__interruptL(@line); |
|
972 |
el = __InstPtr(self)->i_instvars[index]; |
|
973 |
} |
|
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
974 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
975 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
3484 | 976 |
(*codeVal)(BLOCK_ARG, el); |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
977 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
978 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
979 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
980 |
* arg is a compiled block with bytecode - |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
981 |
* directly call interpreter without going through Block>>value |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
982 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
983 |
#ifdef PASS_ARG_POINTER |
3484 | 984 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &el); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
985 |
#else |
3484 | 986 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, el); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
987 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
988 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
989 |
(*val.ilc_func)(aBlock, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
990 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
991 |
nil, &val, |
3484 | 992 |
el); |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
993 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
994 |
} |
3484 | 995 |
n--; |
996 |
index++; |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
997 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
998 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
999 |
# undef BLOCK_ARG |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1000 |
# undef IBLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1001 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1002 |
RETURN (self ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1003 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1004 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1005 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1006 |
* not a block - send it #value: |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1007 |
*/ |
3484 | 1008 |
while (n > 0) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1009 |
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
|
1010 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1011 |
(*val.ilc_func)(aBlock, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1012 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1013 |
nil, &val, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1014 |
__InstPtr(self)->i_instvars[index]); |
3484 | 1015 |
n--; |
1016 |
index++; |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1017 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1018 |
RETURN ( self ); |
155 | 1019 |
} |
1 | 1020 |
} |
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
|
1021 |
%}. |
1 | 1022 |
^ super from:start to:stop do:aBlock |
1023 |
! |
|
1024 |
||
42 | 1025 |
from:start to:stop reverseDo:aBlock |
1026 |
"evaluate the argument, aBlock for the elements starting at index start |
|
1027 |
up to (and including) stop in the collection. Step in reverse order. |
|
1028 |
- reimplemented for speed" |
|
1029 |
||
1030 |
%{ |
|
1031 |
REGISTER OBJFUNC codeVal; |
|
1032 |
REGISTER int index; |
|
1033 |
REGISTER OBJ rHome; |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
1034 |
int nIndex; |
42 | 1035 |
static struct inlineCache val = _ILC1; |
1036 |
int indexLow, indexHigh; |
|
1037 |
||
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
1038 |
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
|
1039 |
&& (__qClass(self) == @global(Array)) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1040 |
&& ((indexLow = __intVal(start)) > 0)) { |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1041 |
indexHigh = __intVal(stop); |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1042 |
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
|
1043 |
if (indexHigh <= nIndex) { |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1044 |
indexLow--; |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1045 |
indexHigh--; |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1046 |
|
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1047 |
if (__isBlockLike(aBlock) |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1048 |
&& (__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
|
1049 |
# undef BLOCK_ARG |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1050 |
#ifdef NEW_BLOCK_CALL |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1051 |
# define BLOCK_ARG aBlock |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1052 |
# define IBLOCK_ARG nil |
42 | 1053 |
#else |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1054 |
# 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
|
1055 |
# 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
|
1056 |
#endif |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1057 |
|
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1058 |
for (index=indexHigh; index >= indexLow; index--) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1059 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1060 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1061 |
if (InterruptPending != nil) __interruptL(@line); |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1062 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1063 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1064 |
(*codeVal)(BLOCK_ARG, __InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1065 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1066 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1067 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1068 |
* arg is a compiled block with bytecode - |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1069 |
* directly call interpreter without going through Block>>value |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1070 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1071 |
#ifdef PASS_ARG_POINTER |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1072 |
__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
|
1073 |
#else |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1074 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __InstPtr(self)->i_instvars[index]); |
42 | 1075 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1076 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1077 |
(*val.ilc_func)(aBlock, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1078 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1079 |
nil, &val, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1080 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1081 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1082 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1083 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1084 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1085 |
# undef BLOCK_ARG |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1086 |
# undef IBLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1087 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1088 |
RETURN (self ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1089 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1090 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1091 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1092 |
* not a block - send it #value: |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1093 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1094 |
for (index=indexHigh; index >= indexLow; index--) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1095 |
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
|
1096 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1097 |
(*val.ilc_func)(aBlock, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1098 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1099 |
nil, &val, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1100 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1101 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1102 |
RETURN ( self ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1103 |
} |
42 | 1104 |
} |
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
|
1105 |
%}. |
42 | 1106 |
^ super from:start to:stop reverseDo:aBlock |
1107 |
! |
|
1108 |
||
554 | 1109 |
keysAndValuesDo:aBlock |
1110 |
"evaluate the argument, aBlock for each element in the collection. |
|
1111 |
Pass both index and element to the block. |
|
1112 |
- reimplemented for speed" |
|
1113 |
||
1114 |
%{ |
|
1115 |
REGISTER OBJFUNC codeVal; |
|
1116 |
REGISTER int index; |
|
1117 |
static struct inlineCache val2 = _ILC2; |
|
1118 |
REGISTER OBJ rHome; |
|
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1119 |
int actualSize; |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1120 |
OBJ myClass; |
554 | 1121 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1122 |
myClass = __qClass(self); |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1123 |
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
|
1124 |
|
2915 | 1125 |
actualSize = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
1126 |
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
|
1127 |
|
2915 | 1128 |
if (index < actualSize) { |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1129 |
if (__isBlockLike(aBlock) |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1130 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(2))) { |
2915 | 1131 |
{ |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1132 |
/* |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1133 |
* 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
|
1134 |
*/ |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1135 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1136 |
|
2915 | 1137 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 1138 |
#ifdef PARANOIA |
2915 | 1139 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 1140 |
#endif |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1141 |
) { |
2254 | 1142 |
|
554 | 1143 |
#ifdef NEW_BLOCK_CALL |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1144 |
# 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
|
1145 |
#else |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1146 |
# define BLOCK_ARG rHome |
2915 | 1147 |
REGISTER OBJ rHome; |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1148 |
|
2915 | 1149 |
rHome = __BlockInstPtr(aBlock)->b_home; |
1150 |
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
|
1151 |
#endif |
2915 | 1152 |
{ |
2878 | 1153 |
OBJ el; |
1154 |
||
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1155 |
while (index < actualSize) { |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1156 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1157 |
el = __InstPtr(self)->i_instvars[index]; |
2915 | 1158 |
if (InterruptPending != nil) goto interruptX; |
2878 | 1159 |
continueX: |
2915 | 1160 |
index++; |
1161 |
(*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
|
1162 |
} |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1163 |
RETURN (self); |
2878 | 1164 |
|
1165 |
interruptX: |
|
1166 |
__interruptL(@line); |
|
1167 |
el = __InstPtr(self)->i_instvars[index]; |
|
1168 |
goto continueX; |
|
2915 | 1169 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1170 |
} |
2915 | 1171 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1172 |
|
2915 | 1173 |
/* |
1174 |
* sorry, must check code-pointer in the loop |
|
1175 |
* it could be recompiled or flushed |
|
1176 |
*/ |
|
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1177 |
# undef BLOCK_ARG |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1178 |
#ifdef NEW_BLOCK_CALL |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1179 |
# define BLOCK_ARG aBlock |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1180 |
# define IBLOCK_ARG nil |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1181 |
#else |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1182 |
# 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
|
1183 |
# 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
|
1184 |
#endif |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1185 |
|
2915 | 1186 |
while (index < actualSize) { |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1187 |
REGISTER OBJFUNC codeVal; |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1188 |
OBJ el; |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1189 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1190 |
if (InterruptPending != nil) __interruptL(@line); |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1191 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1192 |
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
|
1193 |
index++; |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1194 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2915 | 1195 |
(*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
|
1196 |
} else { |
2915 | 1197 |
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
|
1198 |
/* |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1199 |
* 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
|
1200 |
* 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
|
1201 |
*/ |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1202 |
#ifdef PASS_ARG_POINTER |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1203 |
{ |
2915 | 1204 |
OBJ t[2]; |
554 | 1205 |
|
2915 | 1206 |
t[0] = __MKSMALLINT(index); |
1207 |
t[1] = el; |
|
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1208 |
|
2915 | 1209 |
__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
|
1210 |
} |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1211 |
#else |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1212 |
__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
|
1213 |
#endif |
2915 | 1214 |
} else { |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1215 |
(*val2.ilc_func)(aBlock, |
2915 | 1216 |
@symbol(value:value:), |
1217 |
nil, &val2, |
|
1218 |
__MKSMALLINT(index), |
|
1219 |
el); |
|
1220 |
} |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1221 |
} |
2915 | 1222 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1223 |
|
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1224 |
# undef BLOCK_ARG |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1225 |
# undef IBLOCK_ARG |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1226 |
|
2915 | 1227 |
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
|
1228 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1229 |
|
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
|
1230 |
/* |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1231 |
* 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
|
1232 |
*/ |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1233 |
while (index < actualSize) { |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1234 |
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
|
1235 |
|
2915 | 1236 |
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
|
1237 |
|
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1238 |
el = __InstPtr(self)->i_instvars[index]; |
2915 | 1239 |
index++; |
1240 |
(*val2.ilc_func)(aBlock, |
|
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1241 |
@symbol(value:value:), |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1242 |
nil, &val2, |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1243 |
__MKSMALLINT(index), |
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1244 |
el); |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1245 |
} |
2842
1cda44a3660e
oops - #keysAndValuesDo: was from for subclasses with named instVars
Claus Gittinger <cg@exept.de>
parents:
2821
diff
changeset
|
1246 |
RETURN ( self ); |
2915 | 1247 |
} |
554 | 1248 |
} |
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
|
1249 |
%}. |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1250 |
^ super keysAndValuesDo:aBlock |
554 | 1251 |
! |
1252 |
||
543 | 1253 |
reverseDo:aBlock |
1254 |
"evaluate the argument, aBlock for each element in the collection in reverse order. |
|
1255 |
- reimplemented for speed" |
|
1 | 1256 |
|
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
|
1257 |
|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
|
1258 |
|
b2a1dc200c42
allow redefinition of #size in subclasses (optimized methods did not work in this case)
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
1259 |
sz := self size. |
1 | 1260 |
%{ |
1261 |
REGISTER OBJFUNC codeVal; |
|
1262 |
REGISTER int index; |
|
543 | 1263 |
unsigned int nIndex; |
1264 |
int endIndex; |
|
1 | 1265 |
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
|
1266 |
int actualSize; |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1267 |
OBJ myClass; |
1 | 1268 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1269 |
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
|
1270 |
{ |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1271 |
endIndex = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1272 |
actualSize = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1273 |
nIndex = endIndex + __intVal(sz); |
543 | 1274 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1275 |
if (nIndex <= actualSize) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1276 |
if (__isBlockLike(aBlock) |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1277 |
&& (__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
|
1278 |
# undef BLOCK_ARG |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1279 |
#ifdef NEW_BLOCK_CALL |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1280 |
# define BLOCK_ARG aBlock |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1281 |
# define IBLOCK_ARG nil |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1282 |
#else |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1283 |
# 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
|
1284 |
# 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
|
1285 |
#endif |
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1286 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1287 |
for (index=nIndex-1; index >= endIndex; index--) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1288 |
REGISTER OBJFUNC codeVal; |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1289 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1290 |
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
|
1291 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1292 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1293 |
(*codeVal)(BLOCK_ARG, __InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1294 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1295 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1296 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1297 |
* arg is a compiled block with bytecode - |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1298 |
* directly call interpreter without going through Block>>value |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1299 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1300 |
#ifdef PASS_ARG_POINTER |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1301 |
__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
|
1302 |
#else |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1303 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __InstPtr(self)->i_instvars[index]); |
11 | 1304 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1305 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1306 |
(*val.ilc_func)(aBlock, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1307 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1308 |
nil, &val, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1309 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1310 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1311 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1312 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1313 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1314 |
# undef BLOCK_ARG |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1315 |
# undef IBLOCK_ARG |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1316 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1317 |
RETURN (self ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1318 |
} |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1319 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1320 |
/* |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1321 |
* not a block - send it #value: |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1322 |
*/ |
2185
790f4c380343
care for blocks being recompiled or code being flushed, while
Claus Gittinger <cg@exept.de>
parents:
2184
diff
changeset
|
1323 |
for (index=nIndex-1; index >= endIndex; index--) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1324 |
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
|
1325 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1326 |
(*val.ilc_func)(aBlock, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1327 |
@symbol(value:), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1328 |
nil, &val, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1329 |
__InstPtr(self)->i_instvars[index]); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1330 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1331 |
RETURN ( self ); |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1332 |
} |
1 | 1333 |
} |
543 | 1334 |
%}. |
946
35962f2a169b
be prepared for cheaters, subclassing Array returning invalid sizes ...
Claus Gittinger <cg@exept.de>
parents:
945
diff
changeset
|
1335 |
^ super reverseDo:aBlock |
11 | 1336 |
! |
1337 |
||
328 | 1338 |
traverse:aBlock |
1339 |
"Evaluate aBlock for every element that is not an Array, |
|
1123 | 1340 |
and recursively traverse Arrays. |
328 | 1341 |
Implemented here to support better search for selectors in |
1342 |
literal arrays - might be a good idea to move it up in the collection |
|
1343 |
hierarchy, since this may be a useful method for other collections |
|
1344 |
as well." |
|
1345 |
||
1346 |
self do: [:el | |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1347 |
el isArray |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1348 |
ifTrue: [el traverse: aBlock] |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1349 |
ifFalse: [aBlock value: el]] |
328 | 1350 |
|
1351 |
" |
|
1352 |
example: flattening an Array: |
|
1353 |
||
1354 |
|s| |
|
1355 |
||
1356 |
s := WriteStream on:Array new. |
|
1357 |
#(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) traverse:[:el | s nextPut:el]. |
|
1358 |
s contents |
|
1359 |
" |
|
1123 | 1360 |
" |
1361 |
example: deep search |
|
1362 |
||
1363 |
#(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
|
1364 |
el == 10 ifTrue:[Transcript showCR:'found'] |
1123 | 1365 |
] |
1366 |
" |
|
1367 |
||
1368 |
"Modified: 26.3.1996 / 17:08:10 / cg" |
|
543 | 1369 |
! ! |
1370 |
||
1371 |
!Array methodsFor:'filling & replacing'! |
|
1372 |
||
554 | 1373 |
from:index1 to:index2 put:anObject |
1374 |
"reimplemented for speed if receiver is an Array" |
|
1375 |
||
1376 |
%{ /* NOCONTEXT */ |
|
1377 |
||
1378 |
REGISTER int index; |
|
1379 |
unsigned int nIndex; |
|
1380 |
unsigned int endIndex; |
|
1381 |
REGISTER OBJ *dst; |
|
1382 |
||
1383 |
if ((__qClass(self) == Array) |
|
1384 |
&& __bothSmallInteger(index1, index2)) { |
|
1133 | 1385 |
index = __intVal(index1) - 1; |
554 | 1386 |
if (index >= 0) { |
1387 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1133 | 1388 |
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
|
1389 |
|
951
2dd898849a8a
directly call __new if quick allocation fails;
Claus Gittinger <cg@exept.de>
parents:
946
diff
changeset
|
1390 |
if ((endIndex >= index) && (endIndex < nIndex)) { |
1133 | 1391 |
dst = &(__InstPtr(self)->i_instvars[index]); |
554 | 1392 |
#ifdef memset4 |
2865 | 1393 |
{ |
1394 |
int n4 = endIndex-index+1; |
|
1395 |
||
1396 |
memset4(dst, anObject, n4); |
|
1397 |
} |
|
554 | 1398 |
#else |
2865 | 1399 |
# ifdef FAST_MEMSET |
554 | 1400 |
if ((INT)anObject == 0) { |
1401 |
memset(dst, 0, __OBJS2BYTES__(endIndex-index+1)); |
|
2865 | 1402 |
} else |
1403 |
# endif |
|
1404 |
{ |
|
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
|
1405 |
# if defined(UNROLL_LOOPS) |
554 | 1406 |
{ |
1407 |
int i8; |
|
1408 |
||
1409 |
while ((i8 = index + 8) <= endIndex) { |
|
3041 | 1410 |
dst[3] = dst[2] = dst[1] = dst[0] = anObject; |
1411 |
dst[7] = dst[6] = dst[5] = dst[4] = anObject; |
|
554 | 1412 |
dst += 8; |
1413 |
index = i8; |
|
1414 |
} |
|
1415 |
} |
|
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
|
1416 |
# endif |
554 | 1417 |
for (; index <= endIndex; index++) { |
1418 |
*dst++ = anObject; |
|
1419 |
} |
|
1420 |
} |
|
1421 |
#endif |
|
3730
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1422 |
__STORE(self, anObject); |
554 | 1423 |
RETURN ( self ); |
1424 |
} |
|
1425 |
} |
|
1426 |
} |
|
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
|
1427 |
%}. |
554 | 1428 |
^ super from:index1 to:index2 put:anObject |
1429 |
! |
|
1430 |
||
543 | 1431 |
replaceFrom:start to:stop with:aCollection startingAt:repStart |
1168 | 1432 |
"replace elements in the receiver between index start and stop, |
1433 |
with elements taken from replacementCollection starting at repStart. |
|
3234 | 1434 |
Return the receiver. |
1168 | 1435 |
Reimplemented for speed if both receiver and aCollection are Arrays" |
543 | 1436 |
|
1437 |
%{ /* NOCONTEXT */ |
|
1438 |
||
1439 |
unsigned int nIndex; |
|
1440 |
unsigned int repNIndex; |
|
1441 |
int startIndex, stopIndex; |
|
1442 |
REGISTER OBJ *src; |
|
1443 |
REGISTER OBJ *dst; |
|
1444 |
int repStopIndex; |
|
1445 |
REGISTER int repStartIndex; |
|
1446 |
REGISTER OBJ t; |
|
1447 |
REGISTER int count; |
|
1903 | 1448 |
OBJ myClass; |
543 | 1449 |
|
2210 | 1450 |
if ( |
3234 | 1451 |
(__ClassInstPtr((myClass = __qClass(self)))->c_ninstvars == __MKSMALLINT(0)) |
1903 | 1452 |
&& __isNonNilObject(aCollection) |
1453 |
&& (((t = __qClass(aCollection)) == Array) || (t == myClass)) |
|
543 | 1454 |
&& __bothSmallInteger(start, stop) |
2210 | 1455 |
&& __isSmallInteger(repStart) |
1456 |
) { |
|
3234 | 1457 |
startIndex = __intVal(start) - 1; |
1458 |
if (startIndex >= 0) { |
|
1459 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1460 |
stopIndex = __intVal(stop) - 1; |
|
1461 |
count = stopIndex - startIndex + 1; |
|
1903 | 1462 |
|
3234 | 1463 |
if ((count > 0) && (stopIndex < nIndex)) { |
1464 |
repStartIndex = __intVal(repStart) - 1; |
|
1465 |
if (repStartIndex >= 0) { |
|
1466 |
repNIndex = __BYTES2OBJS__(__qSize(aCollection)-OHDR_SIZE); |
|
1467 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
|
1468 |
if (repStopIndex < repNIndex) { |
|
1469 |
src = &(__InstPtr(aCollection)->i_instvars[repStartIndex]); |
|
1470 |
dst = &(__InstPtr(self)->i_instvars[startIndex]); |
|
1471 |
if (aCollection == self) { |
|
1472 |
/* |
|
1473 |
* no need to check stores if copying |
|
1474 |
* from myself |
|
1475 |
*/ |
|
1903 | 1476 |
|
3234 | 1477 |
/* |
1478 |
* take care of overlapping copy |
|
1479 |
* do not depend on memset being smart enough |
|
1480 |
* (some are not ;-) |
|
1481 |
*/ |
|
1482 |
if (src < dst) { |
|
1483 |
/* must do a reverse copy */ |
|
1484 |
src += count; |
|
1485 |
dst += count; |
|
543 | 1486 |
#if defined(UNROLL_LOOPS) |
3234 | 1487 |
while (count > 8) { |
1488 |
dst[-1] = src[-1]; |
|
1489 |
dst[-2] = src[-2]; |
|
1490 |
dst[-3] = src[-3]; |
|
1491 |
dst[-4] = src[-4]; |
|
1492 |
dst[-5] = src[-5]; |
|
1493 |
dst[-6] = src[-6]; |
|
1494 |
dst[-7] = src[-7]; |
|
1495 |
dst[-8] = src[-8]; |
|
1496 |
dst -= 8; src -= 8; |
|
1497 |
count -= 8; |
|
1498 |
} |
|
543 | 1499 |
#endif |
3234 | 1500 |
while (count-- > 0) { |
1501 |
*--dst = *--src; |
|
1502 |
} |
|
1503 |
RETURN ( self ); |
|
1504 |
} |
|
1903 | 1505 |
#ifdef SOFTWARE_PIPELINE |
3234 | 1506 |
{ |
1507 |
OBJ t1; |
|
1903 | 1508 |
|
3234 | 1509 |
/* |
1510 |
* the loop below fetches one longWord behind |
|
1511 |
* this should not be a problem |
|
1512 |
*/ |
|
1513 |
t1 = src[0]; |
|
1514 |
count--; |
|
1515 |
if (count) { |
|
1516 |
dst++; src++; |
|
1517 |
do { |
|
1518 |
dst[-1] = t1; |
|
1519 |
t1 = src[0]; |
|
1520 |
src++; |
|
1521 |
dst++; |
|
1522 |
} while (count--); |
|
1523 |
} else { |
|
1524 |
dst[0] = t1; |
|
1525 |
} |
|
1526 |
} |
|
543 | 1527 |
#else |
1903 | 1528 |
|
1529 |
# ifdef bcopy4 |
|
3234 | 1530 |
bcopy4(src, dst, count); |
1903 | 1531 |
# else |
1532 |
# ifdef FAST_MEMCPY |
|
3234 | 1533 |
bcopy(src, dst, __OBJS2BYTES__(count)); |
1903 | 1534 |
# else |
1535 |
# if defined(UNROLL_LOOPS) |
|
3234 | 1536 |
while (count >= 8) { |
1537 |
dst[0] = src[0]; |
|
1538 |
dst[1] = src[1]; |
|
1539 |
dst[2] = src[2]; |
|
1540 |
dst[3] = src[3]; |
|
1541 |
dst[4] = src[4]; |
|
1542 |
dst[5] = src[5]; |
|
1543 |
dst[6] = src[6]; |
|
1544 |
dst[7] = src[7]; |
|
1545 |
dst += 8; src += 8; |
|
1546 |
count -= 8; |
|
1547 |
} |
|
1903 | 1548 |
# endif |
3234 | 1549 |
while (count--) { |
1550 |
*dst++ = *src++; |
|
1551 |
} |
|
1903 | 1552 |
# endif |
543 | 1553 |
# endif |
1554 |
#endif |
|
3234 | 1555 |
} else { |
1556 |
REGISTER int spc; |
|
543 | 1557 |
|
3234 | 1558 |
spc = __qSpace(self); |
543 | 1559 |
#if defined(UNROLL_LOOPS) |
3730
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1560 |
while (count >= 8) { |
3234 | 1561 |
t = src[0]; dst[0] = t; __STORE_SPC(self, t, spc); |
1562 |
t = src[1]; dst[1] = t; __STORE_SPC(self, t, spc); |
|
1563 |
t = src[2]; dst[2] = t; __STORE_SPC(self, t, spc); |
|
1564 |
t = src[3]; dst[3] = t; __STORE_SPC(self, t, spc); |
|
3730
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1565 |
t = src[4]; dst[4] = t; __STORE_SPC(self, t, spc); |
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1566 |
t = src[5]; dst[5] = t; __STORE_SPC(self, t, spc); |
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1567 |
t = src[6]; dst[6] = t; __STORE_SPC(self, t, spc); |
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1568 |
t = src[7]; dst[7] = t; __STORE_SPC(self, t, spc); |
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
1569 |
count -= 8; src += 8; dst += 8; |
3234 | 1570 |
} |
543 | 1571 |
#endif |
3234 | 1572 |
while (count-- > 0) { |
1573 |
t = *src++; |
|
1574 |
*dst++ = t; |
|
1575 |
__STORE_SPC(self, t, spc); |
|
1576 |
} |
|
1577 |
} |
|
1578 |
RETURN ( self ); |
|
1579 |
} |
|
1580 |
} |
|
1581 |
} |
|
1903 | 1582 |
|
3234 | 1583 |
if (count == 0) { |
1584 |
RETURN ( self ); |
|
1585 |
} |
|
1586 |
} |
|
543 | 1587 |
} |
1588 |
%}. |
|
1589 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
1168 | 1590 |
|
1591 |
"Modified: 13.4.1996 / 12:17:13 / cg" |
|
543 | 1592 |
! ! |
1593 |
||
1594 |
!Array methodsFor:'printing & storing'! |
|
1595 |
||
1596 |
displayString |
|
1597 |
"return a printed representation of the receiver for displaying" |
|
1598 |
||
2915 | 1599 |
|s| |
543 | 1600 |
|
1601 |
(self isLiteral) ifTrue:[ |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1602 |
s := WriteStream on:String new. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1603 |
s writeLimit:5000. |
1498
5083a52b1718
limit displayString to 5000 characters
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
1604 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1605 |
WriteStream writeErrorSignal handle:[:ex | |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1606 |
s writeLimit:nil. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1607 |
s nextPutAll:' ...' |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1608 |
] do:[ |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1609 |
s nextPutAll:'#('. |
2915 | 1610 |
self |
1611 |
do:[:each | s nextPutAll:each displayString.] |
|
1612 |
separatedBy:[s space] |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1613 |
]. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1614 |
s writeLimit:nil. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1615 |
s nextPutAll:')'. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1616 |
^ s contents |
543 | 1617 |
]. |
1618 |
^ super displayString |
|
1083
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
1619 |
|
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
1620 |
" |
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
1621 |
#(1 2 3 4) displayString |
2915 | 1622 |
#(1 2 3 4) printString |
1498
5083a52b1718
limit displayString to 5000 characters
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
1623 |
(Array new:10000) displayString |
1083
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
1624 |
" |
fadaedfa28f8
cosmetic change - no space after last element in displayString
Claus Gittinger <cg@exept.de>
parents:
951
diff
changeset
|
1625 |
|
2915 | 1626 |
"Modified: 12.9.1997 / 22:03:18 / cg" |
543 | 1627 |
! |
1628 |
||
1629 |
storeOn:aStream |
|
1630 |
"append a printed representation of the receiver to aStream, |
|
1631 |
which allows reconstructing it via readFrom:. |
|
1632 |
Redefined to output a somewhat more user friendly string." |
|
1633 |
||
1634 |
self isLiteral ifTrue:[ |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1635 |
aStream nextPutAll:'#('. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1636 |
self do:[:element | element storeOn:aStream. aStream space]. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1637 |
aStream nextPutAll:')' |
543 | 1638 |
] ifFalse:[ |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1639 |
super storeOn:aStream |
543 | 1640 |
] |
1641 |
||
1642 |
" |
|
1643 |
#(1 2 $a 'hello') storeString |
|
588 | 1644 |
#(1 2 $a [1 2 3]) storeString |
543 | 1645 |
" |
588 | 1646 |
|
1647 |
"Created: 20.11.1995 / 11:16:58 / cg" |
|
543 | 1648 |
! ! |
1649 |
||
1650 |
!Array methodsFor:'queries'! |
|
1651 |
||
1652 |
isArray |
|
1653 |
"return true, if the receiver is some kind of array (or weakArray etc). |
|
1654 |
true is returned here" |
|
1655 |
||
1656 |
^ true |
|
1657 |
! |
|
1658 |
||
3226
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1659 |
isEmpty |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1660 |
"return true if the receiver contains no elements. |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1661 |
Reimplemented here for performance." |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1662 |
|
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1663 |
%{ /* NOCONTEXT */ |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1664 |
REGISTER OBJ slf = self; |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1665 |
|
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1666 |
if (__qClass(slf) == Array) { |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1667 |
RETURN ( (__arraySize(slf) == 0) ? true : false); |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1668 |
} |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1669 |
%}. |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1670 |
^ self size == 0 |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1671 |
! |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1672 |
|
543 | 1673 |
isLiteral |
1674 |
"return true, if the receiver can be used as a literal |
|
1675 |
(i.e. can be used in constant arrays)" |
|
1676 |
||
1244 | 1677 |
"/ no, simply returning true here is a mistake: |
1678 |
"/ it could be a subclass of Array |
|
1679 |
"/ (of which the compiler does not know at all ...) |
|
1680 |
||
543 | 1681 |
self class == Array ifFalse:[^ false]. |
1682 |
||
1244 | 1683 |
"/ |
1684 |
"/ care for recursive arrays ... |
|
1685 |
"/ |
|
543 | 1686 |
thisContext isRecursive ifTrue:[^ false]. |
1687 |
self do:[:element | |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1688 |
element isLiteral ifFalse:[^ false] |
543 | 1689 |
]. |
1690 |
^ true |
|
1244 | 1691 |
|
1692 |
"Modified: 22.4.1996 / 12:55:19 / cg" |
|
328 | 1693 |
! |
1694 |
||
3226
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1695 |
notEmpty |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1696 |
"return true if the receiver contains elements. |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1697 |
Reimplemented here for performance." |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1698 |
|
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1699 |
%{ /* NOCONTEXT */ |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1700 |
REGISTER OBJ slf = self; |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1701 |
|
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1702 |
if (__qClass(slf) == Array) { |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1703 |
RETURN ( (__arraySize(slf) != 0) ? true : false); |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1704 |
} |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1705 |
%}. |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1706 |
^ self size ~~ 0 |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1707 |
! |
34a51a534ed5
added tuned versions of isEmpty & notEmpty
Claus Gittinger <cg@exept.de>
parents:
3088
diff
changeset
|
1708 |
|
1243 | 1709 |
refersToLiteral:aLiteral |
1710 |
"return true if the receiver or recursively any array element in the |
|
1711 |
receiver referes to aLiteral" |
|
1712 |
||
543 | 1713 |
self do: [ :el | |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1714 |
el == aLiteral ifTrue:[^true]. |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1715 |
el class == Array ifTrue:[ |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1716 |
(el refersToLiteral: aLiteral) ifTrue: [^true] |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1717 |
] |
543 | 1718 |
]. |
1719 |
^ false |
|
1720 |
||
1721 |
" |
|
1722 |
#(1 2 3) refersToLiteral:#foo |
|
1723 |
#(1 2 3 foo bar baz) refersToLiteral:#foo |
|
1724 |
#(1 2 3 (((bar foo))) bar baz) refersToLiteral:#foo |
|
1725 |
" |
|
1243 | 1726 |
|
1727 |
"Modified: 22.4.1996 / 12:41:46 / cg" |
|
543 | 1728 |
! ! |
1729 |
||
3088 | 1730 |
!Array methodsFor:'searching'! |
543 | 1731 |
|
554 | 1732 |
identityIndexOf:anElement or:alternative |
1733 |
"search the array for anElement or alternative; |
|
1734 |
return the index of anElement if found, or the index of anAlternative, |
|
1735 |
if not found. If anAlternative is also not found, return 0. |
|
1736 |
This is a special interface for high-speed searching in an array |
|
1737 |
and at the same time searching for an empty slot. |
|
1738 |
Do not use this method for your application classes, since it is |
|
1739 |
not portable (i.e. other smalltalks do not offer this)" |
|
1740 |
||
1741 |
%{ /* NOCONTEXT */ |
|
1742 |
||
1743 |
REGISTER int index; |
|
1744 |
REGISTER OBJ o, el1, el2; |
|
1745 |
REGISTER OBJ *op; |
|
1746 |
REGISTER unsigned int nIndex; |
|
1747 |
int altIndex = 0; |
|
1748 |
int nInsts; |
|
1749 |
||
1750 |
index = 0; |
|
1133 | 1751 |
nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
554 | 1752 |
index += nInsts; |
1753 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1754 |
el1 = anElement; el2 = alternative; |
|
1133 | 1755 |
op = & (__InstPtr(self)->i_instvars[index]); |
554 | 1756 |
while (index++ < nIndex) { |
1757 |
if ((o = *op++) == el1) { |
|
1758 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
|
1759 |
} |
|
1760 |
if (o == el2) { |
|
1761 |
if (altIndex == 0) { |
|
1762 |
altIndex = index; |
|
1763 |
} |
|
1764 |
} |
|
1765 |
} |
|
1766 |
RETURN ( __MKSMALLINT(altIndex) ); |
|
1767 |
%} |
|
1768 |
||
1769 |
" |
|
1770 |
#(1 2 3 4 5 6 7 8 9) identityIndexOf:3 or:5 |
|
1771 |
#(1 2 0 4 5 6 7 8 9) identityIndexOf:3 or:5 |
|
1772 |
#(1 2 0 4 5 6 7 3 9) identityIndexOf:3 or:5 |
|
1773 |
#(1 2 3 4 5 nil 7 3 9) identityIndexOf:3 or:nil |
|
1774 |
#(1 2 nil 4 5 6 7 3 9) identityIndexOf:3 or:nil |
|
1775 |
#(1 2 nil 4 5 6 7 8 9) identityIndexOf:3 or:nil |
|
1776 |
#() identityIndexOf:3 or:nil |
|
1777 |
#(1 2) identityIndexOf:3 or:nil |
|
1778 |
" |
|
1779 |
! |
|
1780 |
||
543 | 1781 |
identityIndexOf:anElement startingAt:start |
1782 |
"search the array for anElement; return index if found, 0 otherwise |
|
1783 |
- reimplemented for speed" |
|
1784 |
||
1785 |
%{ /* NOCONTEXT */ |
|
1786 |
||
1787 |
REGISTER int index; |
|
1788 |
REGISTER OBJ el; |
|
1789 |
REGISTER OBJ *op; |
|
1790 |
REGISTER unsigned int nIndex; |
|
1791 |
int nInsts; |
|
1792 |
||
1793 |
if (__isSmallInteger(start)) { |
|
2915 | 1794 |
index = __intVal(start) - 1; |
1795 |
if (index >= 0) { |
|
1796 |
nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
1797 |
index += nInsts; |
|
1798 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1799 |
el = anElement; |
|
1800 |
op = & (__InstPtr(self)->i_instvars[index]); |
|
1903 | 1801 |
|
2213 | 1802 |
#if defined(memsrch4) |
2915 | 1803 |
if (index < nIndex) { |
1804 |
OBJ *p; |
|
2213 | 1805 |
|
2915 | 1806 |
p = memsrch4(op, (INT)el, (nIndex - index)); |
1807 |
if (p) { |
|
1808 |
index += (p - op + 1); |
|
1809 |
RETURN ( __MKSMALLINT(index) ); |
|
1810 |
} |
|
1811 |
} |
|
2213 | 1812 |
#else |
2216 | 1813 |
|
2213 | 1814 |
# if defined(UNROLL_LOOPS) |
2915 | 1815 |
{ |
1816 |
/* |
|
1817 |
* dont argue about those gotos below - they speed up that thing by 30%; |
|
1818 |
* its better to exit the loops below with a goto, |
|
1819 |
* since the generated code will then be: |
|
1820 |
* compare |
|
1821 |
* branch-on-equal found |
|
1822 |
* |
|
1823 |
* otherwise (with return as if-statement), we get: |
|
1824 |
* compare |
|
1825 |
* branch-on-not-equal skipLabel |
|
1826 |
* move-to-return-register true |
|
1827 |
* goto return-label |
|
1828 |
* skipLabel |
|
1829 |
* |
|
1830 |
* therefore, WITH the so-much-blamed goto, we only branch |
|
1831 |
* when found; without the goto, we branch always. |
|
1832 |
* Pipelined CPUs do usually not like taken branches. |
|
1833 |
*/ |
|
2216 | 1834 |
|
2915 | 1835 |
unsigned int i8; |
2216 | 1836 |
|
2915 | 1837 |
while ((i8 = index + 8) < nIndex) { |
1838 |
if (op[0] == el) goto found1; |
|
1839 |
if (op[1] == el) goto found2; |
|
1840 |
if (op[2] == el) goto found3; |
|
1841 |
if (op[3] == el) goto found4; |
|
1842 |
if (op[4] == el) goto found5; |
|
1843 |
if (op[5] == el) goto found6; |
|
1844 |
if (op[6] == el) goto found7; |
|
1845 |
if (op[7] == el) goto found8; |
|
1846 |
index = i8; |
|
1847 |
op += 8; |
|
1848 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1849 |
if (0) { |
2915 | 1850 |
found1: |
1851 |
RETURN ( __MKSMALLINT(index + 1 - nInsts) ); |
|
1852 |
found2: |
|
1853 |
RETURN ( __MKSMALLINT(index + 2 - nInsts) ); |
|
1854 |
found3: |
|
1855 |
RETURN ( __MKSMALLINT(index + 3 - nInsts) ); |
|
1856 |
found4: |
|
1857 |
RETURN ( __MKSMALLINT(index + 4 - nInsts) ); |
|
1858 |
found5: |
|
1859 |
RETURN ( __MKSMALLINT(index + 5 - nInsts) ); |
|
1860 |
found6: |
|
1861 |
RETURN ( __MKSMALLINT(index + 6 - nInsts) ); |
|
1862 |
found7: |
|
1863 |
RETURN ( __MKSMALLINT(index + 7 - nInsts) ); |
|
1864 |
found8: |
|
1865 |
RETURN ( __MKSMALLINT(index + 8 - nInsts) ); |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1866 |
} |
2915 | 1867 |
} |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1868 |
# endif /* UNROLLED_LOOPS */ |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1869 |
|
2915 | 1870 |
while (index++ < nIndex) { |
1871 |
if (*op++ == el) goto found0; |
|
1872 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1873 |
|
2915 | 1874 |
if (0) { |
1875 |
found0: |
|
1876 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
|
1877 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1878 |
#endif /* no memsrch */ |
2915 | 1879 |
} |
1880 |
RETURN ( __MKSMALLINT(0) ); |
|
543 | 1881 |
} |
1882 |
%}. |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1883 |
^ self indexNotInteger |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1884 |
! |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1885 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1886 |
identityIndexOf:anElement startingAt:start endingAt:stop |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1887 |
"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
|
1888 |
return the index if found, 0 otherwise. |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1889 |
- reimplemented for speed when searching in OrderedCollections" |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1890 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1891 |
%{ /* NOCONTEXT */ |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1892 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1893 |
REGISTER int index; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1894 |
REGISTER OBJ el; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1895 |
REGISTER OBJ *op; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1896 |
REGISTER unsigned int lastIndex; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1897 |
unsigned int nIndex; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1898 |
int nInsts; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1899 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1900 |
if (__bothSmallInteger(start, stop)) { |
2915 | 1901 |
index = __intVal(start) - 1; |
1902 |
if (index >= 0) { |
|
1903 |
nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
1904 |
index += nInsts; |
|
1905 |
lastIndex = nInsts + __intVal(stop); |
|
1906 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1907 |
if (nIndex < lastIndex) { |
|
1908 |
lastIndex = nIndex; |
|
1909 |
} |
|
1910 |
el = anElement; |
|
1911 |
op = & (__InstPtr(self)->i_instvars[index]); |
|
2213 | 1912 |
|
1913 |
#if defined(memsrch4) |
|
2915 | 1914 |
if (index < lastIndex) { |
1915 |
OBJ *p; |
|
2216 | 1916 |
|
2915 | 1917 |
p = memsrch4(op, (INT)el, (lastIndex - index)); |
1918 |
if (p) { |
|
1919 |
index += (p - op + 1); |
|
1920 |
RETURN ( __MKSMALLINT(index) ); |
|
1921 |
} |
|
1922 |
} |
|
2216 | 1923 |
#else |
2213 | 1924 |
|
1925 |
# if defined(UNROLL_LOOPS) |
|
2915 | 1926 |
{ |
1927 |
unsigned int i8; |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1928 |
|
2915 | 1929 |
while ((i8 = index + 8) < lastIndex) { |
1930 |
if (op[0] == el) goto found1; |
|
1931 |
if (op[1] == el) goto found2; |
|
1932 |
if (op[2] == el) goto found3; |
|
1933 |
if (op[3] == el) goto found4; |
|
1934 |
if (op[4] == el) goto found5; |
|
1935 |
if (op[5] == el) goto found6; |
|
1936 |
if (op[6] == el) goto found7; |
|
1937 |
if (op[7] == el) goto found8; |
|
1938 |
index = i8; |
|
1939 |
op += 8; |
|
1940 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1941 |
|
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1942 |
if (0) { |
2915 | 1943 |
found1: |
1944 |
RETURN ( __MKSMALLINT(index + 1 - nInsts) ); |
|
1945 |
found2: |
|
1946 |
RETURN ( __MKSMALLINT(index + 2 - nInsts) ); |
|
1947 |
found3: |
|
1948 |
RETURN ( __MKSMALLINT(index + 3 - nInsts) ); |
|
1949 |
found4: |
|
1950 |
RETURN ( __MKSMALLINT(index + 4 - nInsts) ); |
|
1951 |
found5: |
|
1952 |
RETURN ( __MKSMALLINT(index + 5 - nInsts) ); |
|
1953 |
found6: |
|
1954 |
RETURN ( __MKSMALLINT(index + 6 - nInsts) ); |
|
1955 |
found7: |
|
1956 |
RETURN ( __MKSMALLINT(index + 7 - nInsts) ); |
|
1957 |
found8: |
|
1958 |
RETURN ( __MKSMALLINT(index + 8 - nInsts) ); |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1959 |
} |
2915 | 1960 |
} |
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1961 |
# endif /* UNROLL_LOOPS */ |
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1962 |
|
2915 | 1963 |
while (index++ < lastIndex) { |
1964 |
if (*op++ == el) goto found0; |
|
1965 |
} |
|
2715
48beff18cec0
software pipeline element access in enumeration method
Claus Gittinger <cg@exept.de>
parents:
2683
diff
changeset
|
1966 |
|
2915 | 1967 |
if (0) { |
1968 |
found0: |
|
1969 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
|
1970 |
} |
|
2213 | 1971 |
#endif |
2915 | 1972 |
} |
1973 |
RETURN ( __MKSMALLINT(0) ); |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1974 |
} |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1975 |
%}. |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1976 |
^ self indexNotInteger |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1977 |
|
543 | 1978 |
! |
1979 |
||
554 | 1980 |
indexOf:anElement startingAt:start |
1981 |
"search the array for anElement; return index if found, 0 otherwise |
|
1982 |
- reimplemented for speed" |
|
543 | 1983 |
|
554 | 1984 |
|element| |
1985 |
%{ |
|
543 | 1986 |
REGISTER int index; |
554 | 1987 |
unsigned int nIndex, nInsts; |
1988 |
static struct inlineCache eq = _ILC1; |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1989 |
OBJ myClass; |
543 | 1990 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
1991 |
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
|
1992 |
if ( __isSmallInteger(start) ) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1993 |
index = __intVal(start) - 1; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1994 |
if (index >= 0) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1995 |
nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1996 |
index += nInsts; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1997 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
1998 |
if (anElement != nil) { |
1903 | 1999 |
/* |
2000 |
* special kludge to search for a string; |
|
2001 |
* this is so common, that its worth a special case |
|
2002 |
*/ |
|
825
f7b73d83b9d4
optimized search for strings (dont know if its worth it ...)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
2003 |
#define SPECIAL_STRING_OPT |
f7b73d83b9d4
optimized search for strings (dont know if its worth it ...)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
2004 |
#ifdef SPECIAL_STRING_OPT |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2005 |
if (__isString(anElement)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2006 |
while (index < nIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2007 |
element = __InstPtr(self)->i_instvars[index++]; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2008 |
if (__isNonNilObject(element)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2009 |
if (element == anElement) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2010 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2011 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2012 |
if (__qClass(element) == @global(String)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2013 |
if (strcmp(__stringVal(anElement), __stringVal(element)) == 0) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2014 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2015 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2016 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2017 |
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
|
2018 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2019 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2020 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2021 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2022 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2023 |
RETURN (__MKSMALLINT(0)); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2024 |
} |
825
f7b73d83b9d4
optimized search for strings (dont know if its worth it ...)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
2025 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2026 |
while (index < nIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2027 |
element = __InstPtr(self)->i_instvars[index++]; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2028 |
if (element != nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2029 |
if ((element == anElement) |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2030 |
|| ((*eq.ilc_func)(anElement, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2031 |
@symbol(=), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2032 |
nil,&eq, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2033 |
element) == true)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2034 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2035 |
} |
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 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2038 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2039 |
/* |
1903 | 2040 |
* search for nil - do an identity-search |
2041 |
*/ |
|
554 | 2042 |
#if defined(UNROLL_LOOPS) |
2211
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 |
unsigned int i8; |
554 | 2045 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2046 |
while ((i8 = index + 8) < nIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2047 |
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
|
2048 |
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
|
2049 |
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
|
2050 |
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
|
2051 |
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
|
2052 |
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
|
2053 |
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
|
2054 |
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
|
2055 |
index = i8; |
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 |
} |
554 | 2058 |
#endif |
2059 |
||
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2060 |
while (index < nIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2061 |
if (__InstPtr(self)->i_instvars[index++] == nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2062 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2063 |
} |
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 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2066 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2067 |
RETURN (__MKSMALLINT(0)); |
543 | 2068 |
} |
554 | 2069 |
%}. |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
2070 |
^ super indexOf:anElement startingAt:start |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2071 |
! |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2072 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2073 |
indexOf:anElement startingAt:start endingAt:stop |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2074 |
"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
|
2075 |
Return the index if found, 0 otherwise. |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2076 |
- reimplemented for speed when searching in OrderedCollections" |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2077 |
|
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2078 |
|element| |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2079 |
%{ |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2080 |
REGISTER int index; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2081 |
unsigned int lastIndex, nIndex, nInsts; |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2082 |
static struct inlineCache eq = _ILC1; |
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
2083 |
OBJ myClass; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2084 |
|
2184
f25db3e10530
no block-copy operations are allowed with WeakArrays
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
2085 |
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
|
2086 |
if ( __bothSmallInteger(start, stop) ) { |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2087 |
index = __intVal(start) - 1; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2088 |
if (index >= 0) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2089 |
nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2090 |
index += nInsts; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2091 |
lastIndex = nInsts + __intVal(stop); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2092 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2093 |
if (nIndex < lastIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2094 |
lastIndex = nIndex; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2095 |
} |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2096 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2097 |
if (anElement != nil) { |
1903 | 2098 |
/* |
2099 |
* special kludge to search for a string; |
|
2100 |
* this is so common, that its worth a special case |
|
2101 |
*/ |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2102 |
#ifdef SPECIAL_STRING_OPT |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2103 |
if (__isString(anElement)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2104 |
while (index < lastIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2105 |
element = __InstPtr(self)->i_instvars[index++]; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2106 |
if (__isNonNilObject(element)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2107 |
if (element == anElement) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2108 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2109 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2110 |
if (__qClass(element) == @global(String)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2111 |
if (strcmp(__stringVal(anElement), __stringVal(element)) == 0) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2112 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2113 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2114 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2115 |
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
|
2116 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2117 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2118 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2119 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2120 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2121 |
RETURN (__MKSMALLINT(0)); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2122 |
} |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2123 |
#endif |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2124 |
while (index < lastIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2125 |
element = __InstPtr(self)->i_instvars[index++]; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2126 |
if (element != nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2127 |
if ((element == anElement) |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2128 |
|| ((*eq.ilc_func)(anElement, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2129 |
@symbol(=), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2130 |
nil,&eq, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2131 |
element) == true)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2132 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2133 |
} |
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 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2136 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2137 |
if (__isSmallInteger(anElement)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2138 |
/* search for a small number */ |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2139 |
while (index < lastIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2140 |
element = __InstPtr(self)->i_instvars[index++]; |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2141 |
if (element == anElement) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2142 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2143 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2144 |
if (!__isSmallInteger(element)) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2145 |
if ((*eq.ilc_func)(anElement, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2146 |
@symbol(=), |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2147 |
nil,&eq, |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2148 |
element) == true) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2149 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2150 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2151 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2152 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2153 |
} else { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2154 |
/* |
1903 | 2155 |
* search for nil - do an identity-search |
2156 |
*/ |
|
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2157 |
#if defined(UNROLL_LOOPS) |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2158 |
{ |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2159 |
unsigned int i8; |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2160 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2161 |
while ((i8 = index + 8) < lastIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2162 |
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
|
2163 |
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
|
2164 |
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
|
2165 |
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
|
2166 |
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
|
2167 |
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
|
2168 |
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
|
2169 |
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
|
2170 |
index = i8; |
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 |
} |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2173 |
#endif |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2174 |
|
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2175 |
while (index < lastIndex) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2176 |
if (__InstPtr(self)->i_instvars[index++] == nil) { |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2177 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2178 |
} |
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 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2181 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2182 |
} |
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2183 |
RETURN (__MKSMALLINT(0)); |
1158
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2184 |
} |
bf9aec9e892c
added range search (mostly for big orderedCollections)
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
2185 |
%}. |
2211
289095fe875a
oops - must send super indeOf...endingAt:
Claus Gittinger <cg@exept.de>
parents:
2210
diff
changeset
|
2186 |
^ super indexOf:anElement startingAt:start endingAt:stop |
1 | 2187 |
! ! |
543 | 2188 |
|
3088 | 2189 |
!Array methodsFor:'testing'! |
2190 |
||
2191 |
includes:anObject |
|
2192 |
"return true, if the argument, anObject is contained in the array |
|
2193 |
- reimplemented for speed" |
|
2194 |
||
2195 |
|element| |
|
2196 |
||
2197 |
%{ /* NOCONTEXT */ |
|
2198 |
||
2199 |
/* |
|
2200 |
* first, do a quick check using == |
|
2201 |
* this does not need a context or message send. |
|
2202 |
* In many cases this will already find a match. |
|
2203 |
*/ |
|
2204 |
REGISTER int index; |
|
2205 |
REGISTER OBJ o; |
|
2206 |
unsigned int nIndex; |
|
2207 |
static struct inlineCache eq = _ILC1; |
|
2208 |
||
2209 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
2210 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
2211 |
||
2212 |
/* |
|
2213 |
* however, the search is limited to the first 500 |
|
2214 |
* elements, since otherwise, we may spend too much time |
|
2215 |
* searching for identity if an equal value is found early |
|
2216 |
* (except if searching for nil - there is no need for equal compare ...) |
|
2217 |
*/ |
|
2218 |
if (nIndex > 500) { |
|
2219 |
if (o != nil) |
|
2220 |
nIndex = 500; |
|
2221 |
} |
|
2222 |
||
2223 |
o = anObject; |
|
2224 |
||
2225 |
# ifdef memsrch4 |
|
2226 |
if (index < nIndex) { |
|
2227 |
OBJ *p; |
|
2228 |
||
2229 |
p = memsrch4(&(__InstPtr(self)->i_instvars[index]), (INT)o, (nIndex - index)); |
|
2230 |
if (p) { |
|
2231 |
RETURN ( true ); |
|
2232 |
} |
|
2233 |
} |
|
2234 |
||
2235 |
# else |
|
2236 |
/* |
|
2237 |
* dont argue those gotos below - they speed up that thing by 30% |
|
2238 |
* its better to exit the loops below with a goto, |
|
2239 |
* since the generated code will then be: |
|
2240 |
* compare |
|
2241 |
* branch-on-equal found |
|
2242 |
* |
|
2243 |
* otherwise, we get: |
|
2244 |
* compare |
|
2245 |
* branch-on-not-equal skipLabel |
|
2246 |
* move-to-return-register true |
|
2247 |
* goto return-label |
|
2248 |
* skipLabel |
|
2249 |
* |
|
2250 |
* therefore, WITH the so-much-blamed goto, we only branch |
|
2251 |
* when found; without the goto, we branch always. |
|
2252 |
* Pipelined CPUs do usually not like taken branches. |
|
2253 |
* also, all branches are forward, which are usually predicted |
|
2254 |
* as not taken. |
|
2255 |
*/ |
|
2256 |
# if defined(UNROLL_LOOPS) |
|
2257 |
{ |
|
2258 |
unsigned int i8; |
|
2259 |
REGISTER OBJ slf = self; |
|
2260 |
||
2261 |
while ((i8 = index + 8) < nIndex) { |
|
2262 |
if (__InstPtr(slf)->i_instvars[index] == o) goto found; |
|
2263 |
if (__InstPtr(slf)->i_instvars[index+1] == o) goto found; |
|
2264 |
if (__InstPtr(slf)->i_instvars[index+2] == o) goto found; |
|
2265 |
if (__InstPtr(slf)->i_instvars[index+3] == o) goto found; |
|
2266 |
if (__InstPtr(slf)->i_instvars[index+4] == o) goto found; |
|
2267 |
if (__InstPtr(slf)->i_instvars[index+5] == o) goto found; |
|
2268 |
if (__InstPtr(slf)->i_instvars[index+6] == o) goto found; |
|
2269 |
if (__InstPtr(slf)->i_instvars[index+7] == o) goto found; |
|
2270 |
index = i8; |
|
2271 |
} |
|
2272 |
} |
|
2273 |
# endif /* UNROLL_LOOPS */ |
|
2274 |
||
2275 |
while (index < nIndex) { |
|
2276 |
if (__InstPtr(self)->i_instvars[index++] == o) goto found; |
|
2277 |
} |
|
2278 |
if (0) { |
|
2279 |
found: |
|
2280 |
RETURN (true); |
|
2281 |
} |
|
2282 |
||
2283 |
# endif /* no memsrch */ |
|
2284 |
||
2285 |
if (o == nil) { |
|
2286 |
RETURN ( false ); |
|
2287 |
} |
|
2288 |
||
2289 |
/* |
|
2290 |
* then do a slow(er) check using = |
|
2291 |
*/ |
|
2292 |
||
2293 |
/* |
|
2294 |
* sorry: cannot access the stuff from above ... |
|
2295 |
*/ |
|
2296 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
2297 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
2298 |
||
2299 |
while (index < nIndex) { |
|
2300 |
element = __InstPtr(self)->i_instvars[index++]; |
|
2301 |
if (element != nil) { |
|
2302 |
if ((*eq.ilc_func)(anObject, |
|
2303 |
@symbol(=), |
|
2304 |
nil,&eq, |
|
2305 |
element)==true) { |
|
2306 |
RETURN ( true ); |
|
2307 |
} |
|
2308 |
} |
|
2309 |
} |
|
2310 |
%}. |
|
2311 |
^ false |
|
2312 |
! ! |
|
2313 |
||
1903 | 2314 |
!Array class methodsFor:'documentation'! |
626 | 2315 |
|
2316 |
version |
|
3730
375237229a8e
replaceFrom... - unrolled 8 times;
Claus Gittinger <cg@exept.de>
parents:
3500
diff
changeset
|
2317 |
^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.110 1998-08-05 09:24:20 cg Exp $' |
1244 | 2318 |
! ! |