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