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