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