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