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