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