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