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