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