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