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