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