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