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