author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 16:28:41 +0100 | |
changeset 530 | 07d0bce293c9 |
parent 528 | a083413dfbe8 |
child 543 | 09293a92bddb |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
155 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ArrayedCollection variableSubclass:#Array |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
155 | 17 |
category:'Collections-Arrayed' |
1 | 18 |
! |
19 |
||
77 | 20 |
!Array class methodsFor:'documentation'! |
21 |
||
82 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
155 | 25 |
All Rights Reserved |
82 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
version |
|
528
a083413dfbe8
converted version methods from comment-only to returning-a-string
Claus Gittinger <cg@exept.de>
parents:
421
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.40 1995-11-11 14:26:37 cg Exp $' |
82 | 38 |
! |
39 |
||
77 | 40 |
documentation |
41 |
" |
|
155 | 42 |
Instances of Array store general objects; the arrays size is fixed, |
43 |
therefore add:/remove: are not allowed. |
|
399 | 44 |
(actually, #add: is implemented for compatibility with smalltalks which |
45 |
provide it, but it outputs an annoying warning message ...) |
|
46 |
||
155 | 47 |
Access to the individual elements is via an integer index. |
48 |
Since Arrays are used very often in the system, some methods have been tuned by |
|
399 | 49 |
reimplementing them as primitives. |
92 | 50 |
|
51 |
Notice that Array is a built-in class (i.e. the VM knows about its |
|
52 |
representation). Therefore it is NOT possible to add named instance |
|
53 |
variables or change its inheritance. Subclassing is allowed - of course. |
|
54 |
||
55 |
Literal arrays (i.e. array-constants) are entered in source as: |
|
155 | 56 |
#( element1 element2 ... element-n) |
399 | 57 |
where each element must be itself a constant. In addition, true, false and nil |
58 |
are also allowed as array-literal. |
|
59 |
||
92 | 60 |
Examples: |
155 | 61 |
#(1 2 3) |
62 |
#('foo' 2 (1 2) 4) |
|
63 |
#('foo' #(1 2)) |
|
399 | 64 |
#('foo' nil true #true) |
65 |
#('one' two [3 3 3] (4 4 4)) |
|
77 | 66 |
" |
67 |
! ! |
|
68 |
||
3 | 69 |
!Array class methodsFor:'queries'! |
70 |
||
71 |
isBuiltInClass |
|
72 |
"this class is known by the run-time-system" |
|
73 |
||
74 |
^ self == Array |
|
75 |
! ! |
|
76 |
||
249 | 77 |
!Array class methodsFor:'instance creation'! |
78 |
||
345 | 79 |
new:anInteger |
80 |
"return an instance of myself with anInteger indexed variables. |
|
353 | 81 |
Since this is often called, its worth giving it an extra ilc-slot. |
345 | 82 |
Future versions of stc will do this automatically." |
83 |
||
84 |
^ self basicNew:anInteger |
|
85 |
! |
|
86 |
||
249 | 87 |
basicNew:anInteger |
88 |
"return an instance of myself with anInteger indexed variables. |
|
89 |
Since Array-creation is so common (all other collections use them), |
|
90 |
it seems worth to have a specially tuned version here." |
|
91 |
||
92 |
%{ /* NOCONTEXT */ |
|
93 |
||
94 |
OBJ newobj; |
|
95 |
unsigned INT instsize, nInstVars; |
|
96 |
INT nindexedinstvars; |
|
97 |
REGISTER OBJ *op; |
|
98 |
||
99 |
if (__isSmallInteger(anInteger)) { |
|
100 |
nindexedinstvars = _intVal(anInteger); |
|
101 |
if (nindexedinstvars >= 0) { |
|
102 |
nInstVars = _intVal(_ClassInstPtr(self)->c_ninstvars); |
|
103 |
||
104 |
nInstVars += nindexedinstvars; |
|
105 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
357 | 106 |
if (_CanDoQuickAlignedNew(instsize)) { |
107 |
/* |
|
108 |
* the most common case |
|
109 |
*/ |
|
110 |
_qCheckedAlignedNew(newobj, instsize); |
|
111 |
ok: ; |
|
249 | 112 |
_InstPtr(newobj)->o_class = self; |
369 | 113 |
__qSTORE(newobj, self); |
114 |
||
249 | 115 |
#if defined(FAST_ARRAY_MEMSET4) |
116 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars); |
|
117 |
#else |
|
118 |
# if !defined(NEGATIVE_ADDRESSES) |
|
119 |
/* |
|
120 |
* knowing that nil is 0 |
|
121 |
*/ |
|
360 | 122 |
#ifdef XXmips |
249 | 123 |
# undef FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
124 |
# undef FAST_ARRAY_MEMSET_LONGLONG_UNROLLED |
|
125 |
/* seems to be slightly faster */ |
|
126 |
# define FAST_ARRAY_MEMSET |
|
127 |
#endif |
|
128 |
#ifdef sparc |
|
129 |
# define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
|
130 |
#endif |
|
131 |
||
132 |
# if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED) |
|
133 |
op = _InstPtr(newobj)->i_instvars; |
|
134 |
if (nInstVars > 8) { |
|
135 |
*op++ = nil; /* for alignment */ |
|
136 |
nInstVars--; |
|
137 |
while (nInstVars >= 8) { |
|
138 |
*(double *)op = 0.0; |
|
139 |
((double *)op)[1] = 0.0; |
|
140 |
((double *)op)[2] = 0.0; |
|
141 |
((double *)op)[3] = 0.0; |
|
142 |
op += 8; |
|
143 |
nInstVars -= 8; |
|
144 |
} |
|
145 |
} |
|
146 |
while (nInstVars) { |
|
147 |
*op++ = 0; |
|
148 |
nInstVars--; |
|
149 |
} |
|
150 |
# else |
|
151 |
# if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED) |
|
152 |
op = _InstPtr(newobj)->i_instvars; |
|
153 |
if (nInstVars > 8) { |
|
154 |
*op++ = nil; /* for alignment */ |
|
155 |
nInstVars--; |
|
156 |
while (nInstVars >= 8) { |
|
157 |
*(long long *)op = 0; |
|
158 |
((long long *)op)[1] = 0; |
|
159 |
((long long *)op)[2] = 0; |
|
160 |
((long long *)op)[3] = 0; |
|
161 |
op += 8; |
|
162 |
nInstVars -= 8; |
|
163 |
} |
|
164 |
} |
|
165 |
while (nInstVars) { |
|
166 |
*op++ = 0; |
|
167 |
nInstVars--; |
|
168 |
} |
|
169 |
# else |
|
170 |
# if defined(FAST_ARRAY_MEMSET) |
|
171 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
172 |
# else |
|
173 |
op = _InstPtr(newobj)->i_instvars; |
|
174 |
while (nInstVars--) |
|
175 |
*op++ = nil; |
|
176 |
# endif |
|
177 |
# endif |
|
178 |
# endif |
|
179 |
# else |
|
180 |
op = _InstPtr(newobj)->i_instvars; |
|
181 |
while (nInstVars--) |
|
182 |
*op++ = nil; |
|
183 |
# endif |
|
184 |
#endif |
|
185 |
RETURN ( newobj ); |
|
357 | 186 |
} else { |
187 |
/* |
|
188 |
* a GC will happen ... |
|
189 |
* have to protect all context stuff |
|
190 |
* (especially for self, but also for backtrace in case of |
|
191 |
* allocation failure) |
|
192 |
*/ |
|
193 |
PROTECT_CONTEXT |
|
194 |
_qAlignedNew(newobj, instsize, SENDER); |
|
195 |
UNPROTECT_CONTEXT |
|
196 |
if (newobj != nil) { |
|
197 |
goto ok; |
|
198 |
} |
|
249 | 199 |
} |
200 |
} |
|
201 |
} |
|
202 |
%}. |
|
203 |
" |
|
204 |
arrive here if something went wrong ... |
|
205 |
figure out what it was |
|
206 |
" |
|
207 |
(anInteger isMemberOf:SmallInteger) ifFalse:[ |
|
208 |
" |
|
209 |
the argument is either not an integer, |
|
210 |
or a LargeInteger (which means that its definitely too big) |
|
211 |
" |
|
212 |
self error:'argument to new: must be Integer'. |
|
213 |
^ nil |
|
214 |
]. |
|
215 |
(anInteger < 0) ifTrue:[ |
|
216 |
" |
|
217 |
the argument is negative, |
|
218 |
" |
|
219 |
self error:'bad (negative) argument to new:'. |
|
220 |
^ nil |
|
221 |
]. |
|
222 |
" |
|
223 |
memory allocation failed. |
|
224 |
When we arrive here, there was no memory, even after |
|
225 |
a garbage collect. |
|
226 |
This means, that the VM wanted to get some more memory from the |
|
227 |
Operatingsystem, which was not kind enough to give it. |
|
228 |
Bad luck - you should increase the swap space on your machine. |
|
229 |
" |
|
230 |
^ ObjectMemory allocationFailureSignal raise. |
|
360 | 231 |
! ! |
232 |
||
233 |
!Array class ignoredMethodsFor:'instance creation'! |
|
345 | 234 |
|
235 |
with:one |
|
360 | 236 |
"redefined for performance. |
237 |
I really dont know, if it is worth it. |
|
238 |
Detailed measurements may show that this can be removed to save some |
|
239 |
space." |
|
240 |
||
345 | 241 |
%{ /* NOCONTEXT */ |
242 |
if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) { |
|
353 | 243 |
if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(1))) { |
244 |
OBJ newArray; |
|
345 | 245 |
|
353 | 246 |
_qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(1)); |
247 |
_InstPtr(newArray)->o_class = self; |
|
345 | 248 |
_ArrayInstPtr(newArray)->a_element[0] = one; |
369 | 249 |
__qSTORE(newArray, self); |
345 | 250 |
__STORE(newArray, one); |
353 | 251 |
return newArray; |
345 | 252 |
} |
253 |
} |
|
254 |
%}. |
|
255 |
^ super with:one |
|
256 |
! |
|
257 |
||
258 |
with:one with:two |
|
360 | 259 |
"redefined for performance. |
260 |
I really dont know, if it is worth it. |
|
261 |
Detailed measurements may show that this can be removed to save some |
|
262 |
space." |
|
263 |
||
345 | 264 |
%{ /* NOCONTEXT */ |
265 |
if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) { |
|
353 | 266 |
if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(2))) { |
267 |
OBJ newArray; |
|
345 | 268 |
|
353 | 269 |
_qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(2)); |
270 |
_InstPtr(newArray)->o_class = self; |
|
271 |
_ArrayInstPtr(newArray)->a_element[0] = one; |
|
272 |
_ArrayInstPtr(newArray)->a_element[1] = two; |
|
369 | 273 |
__qSTORE(newArray, self); |
353 | 274 |
__STORE(newArray, one); |
275 |
__STORE(newArray, two); |
|
276 |
return newArray; |
|
277 |
} |
|
345 | 278 |
} |
279 |
%}. |
|
280 |
^ super with:one with:two |
|
281 |
! |
|
282 |
||
283 |
with:one with:two with:three |
|
360 | 284 |
"redefined for performance. |
285 |
I really dont know, if it is worth it. |
|
286 |
Detailed measurements may show that this can be removed to save some |
|
287 |
space." |
|
288 |
||
345 | 289 |
%{ /* NOCONTEXT */ |
290 |
if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) { |
|
353 | 291 |
if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(3))) { |
292 |
OBJ newArray; |
|
345 | 293 |
|
353 | 294 |
_qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(3)); |
295 |
_InstPtr(newArray)->o_class = self; |
|
296 |
_ArrayInstPtr(newArray)->a_element[0] = one; |
|
297 |
_ArrayInstPtr(newArray)->a_element[1] = two; |
|
298 |
_ArrayInstPtr(newArray)->a_element[2] = three; |
|
369 | 299 |
__qSTORE(newArray, self); |
353 | 300 |
__STORE(newArray, one); |
301 |
__STORE(newArray, two); |
|
302 |
__STORE(newArray, three); |
|
303 |
return newArray; |
|
304 |
} |
|
345 | 305 |
} |
306 |
%}. |
|
307 |
^ super with:one with:two with:three |
|
308 |
! |
|
309 |
||
310 |
with:one with:two with:three with:four |
|
360 | 311 |
"redefined for performance. |
312 |
I really dont know, if it is worth it. |
|
313 |
Detailed measurements may show that this can be removed to save some |
|
314 |
space." |
|
345 | 315 |
|
316 |
%{ /* NOCONTEXT */ |
|
317 |
if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) { |
|
353 | 318 |
if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(4))) { |
319 |
OBJ newArray; |
|
345 | 320 |
|
353 | 321 |
_qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(4)); |
322 |
_InstPtr(newArray)->o_class = self; |
|
323 |
_ArrayInstPtr(newArray)->a_element[0] = one; |
|
324 |
_ArrayInstPtr(newArray)->a_element[1] = two; |
|
325 |
_ArrayInstPtr(newArray)->a_element[2] = three; |
|
326 |
_ArrayInstPtr(newArray)->a_element[3] = four; |
|
369 | 327 |
__qSTORE(newArray, self); |
353 | 328 |
__STORE(newArray, one); |
329 |
__STORE(newArray, two); |
|
330 |
__STORE(newArray, three); |
|
331 |
__STORE(newArray, four); |
|
332 |
return newArray; |
|
333 |
} |
|
345 | 334 |
} |
335 |
%}. |
|
336 |
^ super with:one with:two with:three with:four |
|
249 | 337 |
! ! |
338 |
||
1 | 339 |
!Array methodsFor:'accessing'! |
340 |
||
77 | 341 |
basicSize |
1 | 342 |
"return the number of indexed elements in the receiver" |
343 |
||
344 |
%{ /* NOCONTEXT */ |
|
345 |
||
345 | 346 |
RETURN ( __MKSMALLINT(_arraySize(self) - _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars) )); |
1 | 347 |
%} |
348 |
! |
|
349 |
||
353 | 350 |
size |
351 |
"return the number of indexed elements in the receiver. |
|
352 |
Reimplemented here to avoid the additional size->basicSize send |
|
353 |
(which we can do here, since size is obviously not redefined in a subclass). |
|
354 |
This method is the same as basicSize." |
|
355 |
||
356 |
%{ /* NOCONTEXT */ |
|
357 |
||
358 |
RETURN ( __MKSMALLINT(_arraySize(self) - _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars) )); |
|
359 |
%} |
|
360 |
! |
|
361 |
||
77 | 362 |
basicAt:index |
1 | 363 |
"return the indexed instance variable with index, anInteger |
364 |
- added here for speed" |
|
365 |
||
366 |
%{ /* NOCONTEXT */ |
|
367 |
||
368 |
REGISTER int indx; |
|
92 | 369 |
REGISTER unsigned int nIndex; |
11 | 370 |
OBJ cls; |
1 | 371 |
|
249 | 372 |
if (__isSmallInteger(index)) { |
155 | 373 |
indx = _intVal(index) - 1; |
374 |
if (indx >= 0) { |
|
328 | 375 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
376 |
if ((cls = __qClass(self)) != Array) |
|
155 | 377 |
indx += _intVal(_ClassInstPtr(cls)->c_ninstvars); |
378 |
if (indx < nIndex) { |
|
379 |
RETURN ( _InstPtr(self)->i_instvars[indx] ); |
|
380 |
} |
|
381 |
} |
|
1 | 382 |
} |
383 |
%} |
|
384 |
. |
|
77 | 385 |
^ super basicAt:index |
1 | 386 |
! |
387 |
||
353 | 388 |
at:index |
389 |
"return the indexed instance variable with index, anInteger. |
|
390 |
Reimplemented here to avoid the additional at:->basicAt: send |
|
391 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
392 |
This method is the same as at:." |
|
393 |
||
394 |
%{ /* NOCONTEXT */ |
|
395 |
||
396 |
REGISTER int indx; |
|
397 |
REGISTER unsigned int nIndex; |
|
398 |
OBJ cls; |
|
399 |
||
400 |
if (__isSmallInteger(index)) { |
|
401 |
indx = _intVal(index) - 1; |
|
402 |
if (indx >= 0) { |
|
403 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
404 |
if ((cls = __qClass(self)) != Array) |
|
405 |
indx += _intVal(_ClassInstPtr(cls)->c_ninstvars); |
|
406 |
if (indx < nIndex) { |
|
407 |
RETURN ( _InstPtr(self)->i_instvars[indx] ); |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
%}. |
|
412 |
^ super at:index |
|
413 |
! |
|
414 |
||
77 | 415 |
basicAt:index put:anObject |
1 | 416 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
417 |
- added here for speed" |
|
418 |
||
419 |
%{ /* NOCONTEXT */ |
|
420 |
||
421 |
REGISTER int indx; |
|
92 | 422 |
REGISTER unsigned int nIndex; |
11 | 423 |
OBJ cls; |
1 | 424 |
|
249 | 425 |
if (__isSmallInteger(index)) { |
155 | 426 |
indx = _intVal(index) - 1; |
427 |
if (indx >= 0) { |
|
328 | 428 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
429 |
if ((cls = __qClass(self)) != Array) |
|
155 | 430 |
indx += _intVal(_ClassInstPtr(cls)->c_ninstvars); |
431 |
if (indx < nIndex) { |
|
432 |
_InstPtr(self)->i_instvars[indx] = anObject; |
|
433 |
__STORE(self, anObject); |
|
434 |
RETURN ( anObject ); |
|
435 |
} |
|
436 |
} |
|
1 | 437 |
} |
438 |
%} |
|
439 |
. |
|
77 | 440 |
^ super basicAt:index put:anObject |
353 | 441 |
! |
442 |
||
443 |
at:index put:anObject |
|
444 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
445 |
Reimplemented here to avoid the additional at:put:->basicAt:put: send |
|
446 |
(which we can do here, since at: is obviously not redefined in a subclass). |
|
447 |
This method is the same as at:." |
|
448 |
||
449 |
%{ /* NOCONTEXT */ |
|
450 |
||
451 |
REGISTER int indx; |
|
452 |
REGISTER unsigned int nIndex; |
|
453 |
OBJ cls; |
|
454 |
||
455 |
if (__isSmallInteger(index)) { |
|
456 |
indx = _intVal(index) - 1; |
|
457 |
if (indx >= 0) { |
|
458 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
459 |
if ((cls = __qClass(self)) != Array) |
|
460 |
indx += _intVal(_ClassInstPtr(cls)->c_ninstvars); |
|
461 |
if (indx < nIndex) { |
|
462 |
_InstPtr(self)->i_instvars[indx] = anObject; |
|
463 |
__STORE(self, anObject); |
|
464 |
RETURN ( anObject ); |
|
465 |
} |
|
466 |
} |
|
467 |
} |
|
468 |
%}. |
|
469 |
^ super at:index put:anObject |
|
1 | 470 |
! ! |
471 |
||
11 | 472 |
!Array methodsFor:'converting'! |
473 |
||
474 |
asArray |
|
475 |
"return the receiver as an array" |
|
476 |
||
477 |
"could be an instance of a subclass..." |
|
478 |
self class == Array ifTrue:[ |
|
155 | 479 |
^ self |
11 | 480 |
]. |
481 |
^ super asArray |
|
482 |
! ! |
|
483 |
||
1 | 484 |
!Array methodsFor:'copying'! |
485 |
||
486 |
copyWith:something |
|
220 | 487 |
"return a new collection containing the receivers elements |
488 |
and the single new element, newElement. |
|
489 |
This is different from concatentation, which expects another collection |
|
490 |
as argument, but equivalent to copy-and-addLast. |
|
370 | 491 |
Reimplemented for speed if receiver is an Array. |
492 |
(since the inherited copyWith uses replaceFromTo:, which is also |
|
493 |
tuned, it is questionable, if we need this)" |
|
494 |
||
495 |
%{ /* NOCONTEXT */ |
|
11 | 496 |
OBJ nObj, element; |
92 | 497 |
unsigned int sz; |
498 |
unsigned int nIndex; |
|
11 | 499 |
REGISTER OBJ *srcP, *dstP; |
293 | 500 |
REGISTER int spc; |
1 | 501 |
|
328 | 502 |
if (__qClass(self) == Array) { |
503 |
sz = __qSize(self) + sizeof(OBJ); |
|
155 | 504 |
PROTECT(something); |
370 | 505 |
PROTECT(self); |
155 | 506 |
_qAlignedNew(nObj, sz, __context); |
370 | 507 |
UNPROTECT(self); |
155 | 508 |
UNPROTECT(something); |
92 | 509 |
|
155 | 510 |
if (nObj) { |
511 |
_InstPtr(nObj)->o_class = Array; |
|
1 | 512 |
|
155 | 513 |
nIndex = __BYTES2OBJS__(sz - OHDR_SIZE - sizeof(OBJ)); |
370 | 514 |
/* |
515 |
* sorry: |
|
516 |
* cannot use bcopy, since we must take care of stores ... |
|
517 |
* could check for: notRemembered + inOld + notLifoRem |
|
518 |
* + not incrGCRunning |
|
519 |
* but copyWith: is not heavily used by real programmers ... |
|
520 |
*/ |
|
521 |
spc = __qSpace(nObj); |
|
155 | 522 |
srcP = _ArrayInstPtr(self)->a_element; |
523 |
dstP = _ArrayInstPtr(nObj)->a_element; |
|
393 | 524 |
#ifdef UNROLL_LOOPS |
525 |
while (nIndex >= 4) { |
|
526 |
element = srcP[0]; |
|
527 |
dstP[0] = element; |
|
528 |
__STORE_SPC(nObj, element, spc); |
|
529 |
element = srcP[1]; |
|
530 |
dstP[1] = element; |
|
531 |
__STORE_SPC(nObj, element, spc); |
|
532 |
element = srcP[2]; |
|
533 |
dstP[2] = element; |
|
534 |
__STORE_SPC(nObj, element, spc); |
|
535 |
element = srcP[3]; |
|
536 |
dstP[3] = element; |
|
537 |
__STORE_SPC(nObj, element, spc); |
|
538 |
srcP += 4; |
|
539 |
dstP += 4; |
|
540 |
nIndex -= 4; |
|
541 |
} |
|
542 |
#endif |
|
155 | 543 |
while (nIndex--) { |
544 |
element = *srcP++; |
|
545 |
*dstP++ = element; |
|
293 | 546 |
__STORE_SPC(nObj, element, spc); |
155 | 547 |
} |
548 |
*dstP = something; |
|
293 | 549 |
__STORE_SPC(nObj, something, spc); |
155 | 550 |
RETURN ( nObj ); |
551 |
} |
|
1 | 552 |
} |
553 |
%} |
|
554 |
. |
|
555 |
^ super copyWith:something |
|
556 |
! ! |
|
557 |
||
359 | 558 |
!Array ignoredMethodsFor:'filling & replacing'! |
559 |
||
560 |
atAllPut:anObject |
|
561 |
"reimplemented for speed if receiver is an Array" |
|
562 |
||
563 |
%{ /* NOCONTEXT */ |
|
564 |
||
565 |
unsigned int nIndex; |
|
566 |
REGISTER OBJ *dst; |
|
567 |
||
568 |
if (__qClass(self) == Array) { |
|
569 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
570 |
dst = __ArrayInstPtr(self)->a_element; |
|
571 |
#ifdef memset4 |
|
572 |
memset4(dst, anObject, nIndex); |
|
573 |
__STORE(self, anObject); |
|
574 |
#else |
|
575 |
if ((INT)anObject == 0) { |
|
576 |
memset(dst, 0, __OBJS2BYTES__(nIndex)); |
|
577 |
} else { |
|
393 | 578 |
#ifdef UNROLL_LOOPS |
579 |
while (nIndex >= 8) { |
|
580 |
dst[0] = anObject; |
|
581 |
dst[1] = anObject; |
|
582 |
dst[2] = anObject; |
|
583 |
dst[3] = anObject; |
|
584 |
dst[4] = anObject; |
|
585 |
dst[5] = anObject; |
|
586 |
dst[6] = anObject; |
|
587 |
dst[7] = anObject; |
|
588 |
dst += 8; |
|
589 |
nIndex -= 8; |
|
590 |
} |
|
591 |
#endif |
|
359 | 592 |
for (; nIndex; nIndex--) { |
593 |
*dst++ = anObject; |
|
594 |
} |
|
595 |
__STORE(self, anObject); |
|
596 |
} |
|
597 |
#endif |
|
598 |
RETURN ( self ); |
|
599 |
} |
|
600 |
%}. |
|
601 |
^ super atAllPut:anObject |
|
602 |
! ! |
|
603 |
||
1 | 604 |
!Array methodsFor:'filling & replacing'! |
605 |
||
606 |
from:index1 to:index2 put:anObject |
|
607 |
"reimplemented for speed if receiver is an Array" |
|
608 |
||
609 |
%{ /* NOCONTEXT */ |
|
610 |
||
611 |
REGISTER int index; |
|
92 | 612 |
unsigned int nIndex; |
613 |
unsigned int endIndex; |
|
1 | 614 |
REGISTER OBJ *dst; |
615 |
||
328 | 616 |
if ((__qClass(self) == Array) |
249 | 617 |
&& __bothSmallInteger(index1, index2)) { |
155 | 618 |
index = _intVal(index1) - 1; |
619 |
if (index >= 0) { |
|
328 | 620 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
155 | 621 |
endIndex = _intVal(index2) - 1; |
622 |
if (endIndex < nIndex) { |
|
623 |
dst = &(_InstPtr(self)->i_instvars[index]); |
|
1 | 624 |
#ifdef memset4 |
155 | 625 |
memset4(dst, anObject, (endIndex-index+1)); |
626 |
__STORE(self, anObject); |
|
1 | 627 |
#else |
155 | 628 |
if ((INT)anObject == 0) { |
629 |
memset(dst, 0, __OBJS2BYTES__(endIndex-index+1)); |
|
630 |
} else { |
|
388 | 631 |
#if defined(UNROLL_LOOPS) |
370 | 632 |
{ |
633 |
int i8; |
|
634 |
||
635 |
while ((i8 = index + 8) <= endIndex) { |
|
636 |
dst[0] = anObject; |
|
637 |
dst[1] = anObject; |
|
638 |
dst[2] = anObject; |
|
639 |
dst[3] = anObject; |
|
640 |
dst[4] = anObject; |
|
641 |
dst[5] = anObject; |
|
642 |
dst[6] = anObject; |
|
643 |
dst[7] = anObject; |
|
644 |
dst += 8; |
|
645 |
index = i8; |
|
646 |
} |
|
647 |
} |
|
648 |
#endif |
|
155 | 649 |
for (; index <= endIndex; index++) { |
650 |
*dst++ = anObject; |
|
651 |
} |
|
652 |
__STORE(self, anObject); |
|
653 |
} |
|
1 | 654 |
#endif |
155 | 655 |
RETURN ( self ); |
656 |
} |
|
657 |
} |
|
1 | 658 |
} |
659 |
%} |
|
660 |
. |
|
661 |
^ super from:index1 to:index2 put:anObject |
|
662 |
! |
|
663 |
||
664 |
replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
665 |
"reimplemented for speed if both receiver and aCollection are Arrays" |
|
666 |
||
667 |
%{ /* NOCONTEXT */ |
|
668 |
||
92 | 669 |
unsigned int nIndex; |
670 |
unsigned int repNIndex; |
|
1 | 671 |
int startIndex, stopIndex; |
672 |
REGISTER OBJ *src; |
|
673 |
REGISTER OBJ *dst; |
|
674 |
int repStopIndex; |
|
675 |
REGISTER int repStartIndex; |
|
676 |
REGISTER OBJ t; |
|
677 |
REGISTER int count; |
|
678 |
||
302 | 679 |
|
345 | 680 |
if ((_ClassInstPtr(__qClass(self))->c_ninstvars == __MKSMALLINT(0)) |
328 | 681 |
&& (((t = __Class(aCollection)) == Array) || (t == __qClass(self))) |
249 | 682 |
&& __bothSmallInteger(start, stop) |
683 |
&& __isSmallInteger(repStart)) { |
|
155 | 684 |
startIndex = _intVal(start) - 1; |
685 |
if (startIndex >= 0) { |
|
328 | 686 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
155 | 687 |
stopIndex = _intVal(stop) - 1; |
688 |
count = stopIndex - startIndex + 1; |
|
689 |
if (count == 0) { |
|
690 |
RETURN ( self ); |
|
691 |
} |
|
692 |
if ((count > 0) && (stopIndex < nIndex)) { |
|
693 |
repStartIndex = _intVal(repStart) - 1; |
|
694 |
if (repStartIndex >= 0) { |
|
328 | 695 |
repNIndex = __BYTES2OBJS__(__qSize(aCollection)-OHDR_SIZE); |
155 | 696 |
repStopIndex = repStartIndex + (stopIndex - startIndex); |
697 |
if (repStopIndex < repNIndex) { |
|
698 |
src = &(_InstPtr(aCollection)->i_instvars[repStartIndex]); |
|
699 |
dst = &(_InstPtr(self)->i_instvars[startIndex]); |
|
700 |
if (aCollection == self) { |
|
370 | 701 |
/* |
702 |
* no need to check stores if copying |
|
703 |
* from myself |
|
704 |
*/ |
|
705 |
/* |
|
706 |
* take care of overlapping copy |
|
707 |
* do not depend on memset being smart enough |
|
708 |
* (some are not ;-) |
|
709 |
*/ |
|
155 | 710 |
if (src < dst) { |
711 |
/* must do a reverse copy */ |
|
712 |
src += count; |
|
713 |
dst += count; |
|
388 | 714 |
#if defined(UNROLL_LOOPS) |
370 | 715 |
while (count > 8) { |
716 |
dst[-1] = src[-1]; |
|
717 |
dst[-2] = src[-2]; |
|
718 |
dst[-3] = src[-3]; |
|
719 |
dst[-4] = src[-4]; |
|
720 |
dst[-5] = src[-5]; |
|
721 |
dst[-6] = src[-6]; |
|
722 |
dst[-7] = src[-7]; |
|
723 |
dst[-8] = src[-8]; |
|
724 |
dst -= 8; src -= 8; |
|
725 |
count -= 8; |
|
726 |
} |
|
727 |
#endif |
|
155 | 728 |
while (count-- > 0) { |
729 |
*--dst = *--src; |
|
730 |
} |
|
731 |
RETURN ( self ); |
|
732 |
} |
|
1 | 733 |
#ifdef bcopy4 |
155 | 734 |
bcopy4(src, dst, count); |
1 | 735 |
#else |
736 |
# ifdef FAST_MEMCPY |
|
155 | 737 |
bcopy(src, dst, __OBJS2BYTES__(count)); |
1 | 738 |
# else |
155 | 739 |
while (count--) { |
740 |
*dst++ = *src++; |
|
741 |
} |
|
1 | 742 |
# endif |
743 |
#endif |
|
155 | 744 |
} else { |
302 | 745 |
REGISTER int spc; |
293 | 746 |
|
325 | 747 |
spc = __qSpace(self); |
388 | 748 |
#if defined(UNROLL_LOOPS) |
370 | 749 |
while (count >= 4) { |
750 |
t = src[0]; dst[0] = t; __STORE_SPC(self, t, spc); |
|
751 |
t = src[1]; dst[1] = t; __STORE_SPC(self, t, spc); |
|
752 |
t = src[2]; dst[2] = t; __STORE_SPC(self, t, spc); |
|
753 |
t = src[3]; dst[3] = t; __STORE_SPC(self, t, spc); |
|
754 |
count -= 4; src += 4; dst += 4; |
|
755 |
} |
|
756 |
#endif |
|
155 | 757 |
while (count-- > 0) { |
758 |
t = *src++; |
|
759 |
*dst++ = t; |
|
293 | 760 |
__STORE_SPC(self, t, spc); |
155 | 761 |
} |
762 |
} |
|
763 |
RETURN ( self ); |
|
764 |
} |
|
765 |
} |
|
766 |
} |
|
767 |
} |
|
1 | 768 |
} |
370 | 769 |
%}. |
1 | 770 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart |
771 |
! ! |
|
772 |
||
275 | 773 |
!Array methodsFor:'queries'! |
774 |
||
370 | 775 |
isArray |
776 |
"return true, if the receiver is some kind of array (or weakArray etc). |
|
777 |
true is returned here" |
|
778 |
||
779 |
^ true |
|
780 |
! |
|
781 |
||
275 | 782 |
isLiteral |
783 |
"return true, if the receiver can be used as a literal |
|
784 |
(i.e. can be used in constant arrays)" |
|
785 |
||
786 |
"no, subclasses of array are not" |
|
787 |
self class == Array ifFalse:[^ false]. |
|
788 |
||
789 |
thisContext isRecursive ifTrue:[^ false]. |
|
790 |
||
791 |
self do:[:element | |
|
792 |
element isLiteral ifFalse:[^ false] |
|
793 |
]. |
|
794 |
^ true |
|
328 | 795 |
! |
796 |
||
797 |
refersToLiteral: aLiteral |
|
798 |
self do: [ :el | |
|
799 |
el == aLiteral ifTrue:[^true]. |
|
800 |
el class == Array ifTrue:[ |
|
801 |
(el refersToLiteral: aLiteral) ifTrue: [^true] |
|
802 |
] |
|
803 |
]. |
|
804 |
^ false |
|
805 |
||
806 |
" |
|
807 |
#(1 2 3) refersToLiteral:#foo |
|
808 |
#(1 2 3 foo bar baz) refersToLiteral:#foo |
|
809 |
#(1 2 3 (((bar foo))) bar baz) refersToLiteral:#foo |
|
810 |
" |
|
275 | 811 |
! ! |
812 |
||
1 | 813 |
!Array methodsFor:'testing'! |
814 |
||
815 |
includes:anObject |
|
816 |
"return true, if the argument, anObject is contained in the array |
|
817 |
- reimplemented for speed" |
|
818 |
||
819 |
|element| |
|
820 |
||
821 |
%{ /* NOCONTEXT */ |
|
822 |
||
92 | 823 |
/* |
824 |
* first, do a quick check using == |
|
302 | 825 |
* this does not need a context or message send. |
370 | 826 |
* In many cases this will already find a match. |
92 | 827 |
*/ |
1 | 828 |
REGISTER int index; |
829 |
REGISTER OBJ o; |
|
92 | 830 |
unsigned int nIndex; |
1 | 831 |
|
328 | 832 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
833 |
index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
|
1 | 834 |
|
370 | 835 |
/* |
836 |
* however, the search is limited to the first 1000 |
|
837 |
* elements, since otherwise, we may spend too much time |
|
838 |
* searching for identity if an equal value is found early |
|
839 |
*/ |
|
840 |
if (nIndex > 1000) nIndex = 1000; |
|
841 |
||
1 | 842 |
o = anObject; |
388 | 843 |
#if defined(UNROLL_LOOPS) |
369 | 844 |
{ |
845 |
unsigned int i8; |
|
846 |
||
847 |
while ((i8 = index + 8) < nIndex) { |
|
848 |
if (_InstPtr(self)->i_instvars[index] == o) { RETURN ( true ); } |
|
849 |
if (_InstPtr(self)->i_instvars[index+1] == o) { RETURN ( true ); } |
|
850 |
if (_InstPtr(self)->i_instvars[index+2] == o) { RETURN ( true ); } |
|
851 |
if (_InstPtr(self)->i_instvars[index+3] == o) { RETURN ( true ); } |
|
852 |
if (_InstPtr(self)->i_instvars[index+4] == o) { RETURN ( true ); } |
|
853 |
if (_InstPtr(self)->i_instvars[index+5] == o) { RETURN ( true ); } |
|
854 |
if (_InstPtr(self)->i_instvars[index+6] == o) { RETURN ( true ); } |
|
855 |
if (_InstPtr(self)->i_instvars[index+7] == o) { RETURN ( true ); } |
|
856 |
index = i8; |
|
857 |
} |
|
365 | 858 |
} |
859 |
#endif |
|
1 | 860 |
while (index < nIndex) { |
155 | 861 |
if (_InstPtr(self)->i_instvars[index++] == o) { |
862 |
RETURN ( true ); |
|
863 |
} |
|
1 | 864 |
} |
865 |
if (o == nil) { |
|
155 | 866 |
RETURN ( false ); |
1 | 867 |
} |
868 |
%} |
|
869 |
. |
|
870 |
%{ |
|
92 | 871 |
/* |
872 |
* then do a slow(er) check using = |
|
873 |
*/ |
|
1 | 874 |
REGISTER int index; |
92 | 875 |
unsigned int nIndex; |
1 | 876 |
static struct inlineCache eq = _ILC1; |
877 |
||
370 | 878 |
/* |
879 |
* sorry: cannot access the stuff from above ... |
|
880 |
*/ |
|
328 | 881 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
882 |
index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
|
1 | 883 |
|
884 |
while (index < nIndex) { |
|
155 | 885 |
element = _InstPtr(self)->i_instvars[index++]; |
886 |
if (element != nil) { |
|
887 |
if ((*eq.ilc_func)(anObject, |
|
888 |
@symbol(=), |
|
889 |
CON_COMMA nil,&eq, |
|
890 |
element)==true) { |
|
891 |
RETURN ( true ); |
|
892 |
} |
|
893 |
} |
|
1 | 894 |
} |
356 | 895 |
%}. |
1 | 896 |
^ false |
897 |
! |
|
898 |
||
899 |
indexOf:anElement startingAt:start |
|
900 |
"search the array for anElement; return index if found, 0 otherwise |
|
901 |
- reimplemented for speed" |
|
902 |
||
903 |
|element| |
|
904 |
%{ |
|
905 |
REGISTER int index; |
|
92 | 906 |
unsigned int nIndex, nInsts; |
1 | 907 |
static struct inlineCache eq = _ILC1; |
908 |
||
249 | 909 |
if (__isSmallInteger(start)) { |
155 | 910 |
index = _intVal(start) - 1; |
911 |
if (index >= 0) { |
|
328 | 912 |
nInsts = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
155 | 913 |
index += nInsts; |
328 | 914 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
155 | 915 |
if (anElement != nil) { |
916 |
while (index < nIndex) { |
|
917 |
element = _InstPtr(self)->i_instvars[index++]; |
|
918 |
if (element != nil) { |
|
919 |
if ((element == anElement) |
|
920 |
|| ((*eq.ilc_func)(anElement, |
|
921 |
@symbol(=), |
|
922 |
CON_COMMA nil,&eq, |
|
923 |
element) == true)) { |
|
345 | 924 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
155 | 925 |
} |
926 |
} |
|
927 |
} |
|
928 |
} else { |
|
929 |
/* search for nil */ |
|
388 | 930 |
#if defined(UNROLL_LOOPS) |
379 | 931 |
{ |
370 | 932 |
unsigned int i8; |
933 |
||
934 |
while ((i8 = index + 8) < nIndex) { |
|
379 | 935 |
if (_InstPtr(self)->i_instvars[index] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 1) ); } |
936 |
if (_InstPtr(self)->i_instvars[index+1] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 2) ); } |
|
937 |
if (_InstPtr(self)->i_instvars[index+2] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 3) ); } |
|
938 |
if (_InstPtr(self)->i_instvars[index+3] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 4) ); } |
|
939 |
if (_InstPtr(self)->i_instvars[index+4] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 5) ); } |
|
940 |
if (_InstPtr(self)->i_instvars[index+5] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 6) ); } |
|
941 |
if (_InstPtr(self)->i_instvars[index+6] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 7) ); } |
|
942 |
if (_InstPtr(self)->i_instvars[index+7] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 8) ); } |
|
943 |
index = i8; |
|
944 |
} |
|
945 |
} |
|
370 | 946 |
#endif |
947 |
||
155 | 948 |
while (index < nIndex) { |
949 |
if (_InstPtr(self)->i_instvars[index++] == nil) { |
|
345 | 950 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
155 | 951 |
} |
952 |
} |
|
953 |
} |
|
954 |
} |
|
1 | 955 |
} |
356 | 956 |
%}. |
1 | 957 |
^ 0 |
958 |
! |
|
959 |
||
960 |
identityIndexOf:anElement startingAt:start |
|
961 |
"search the array for anElement; return index if found, 0 otherwise |
|
962 |
- reimplemented for speed" |
|
963 |
||
964 |
%{ /* NOCONTEXT */ |
|
965 |
||
966 |
REGISTER int index; |
|
967 |
REGISTER OBJ el; |
|
968 |
REGISTER OBJ *op; |
|
92 | 969 |
REGISTER unsigned int nIndex; |
1 | 970 |
int nInsts; |
971 |
||
249 | 972 |
if (__isSmallInteger(start)) { |
155 | 973 |
index = _intVal(start) - 1; |
974 |
if (index >= 0) { |
|
328 | 975 |
nInsts = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
155 | 976 |
index += nInsts; |
328 | 977 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
155 | 978 |
el = anElement; |
979 |
op = & (_InstPtr(self)->i_instvars[index]); |
|
388 | 980 |
#if defined(UNROLL_LOOPS) |
369 | 981 |
{ |
982 |
unsigned int i8; |
|
983 |
||
984 |
while ((i8 = index + 8) < nIndex) { |
|
985 |
if (op[0] == el) { RETURN ( __MKSMALLINT(index + 1 - nInsts) ); } |
|
986 |
if (op[1] == el) { RETURN ( __MKSMALLINT(index + 2 - nInsts) ); } |
|
987 |
if (op[2] == el) { RETURN ( __MKSMALLINT(index + 3 - nInsts) ); } |
|
988 |
if (op[3] == el) { RETURN ( __MKSMALLINT(index + 4 - nInsts) ); } |
|
989 |
if (op[4] == el) { RETURN ( __MKSMALLINT(index + 5 - nInsts) ); } |
|
990 |
if (op[5] == el) { RETURN ( __MKSMALLINT(index + 6 - nInsts) ); } |
|
991 |
if (op[6] == el) { RETURN ( __MKSMALLINT(index + 7 - nInsts) ); } |
|
992 |
if (op[7] == el) { RETURN ( __MKSMALLINT(index + 8 - nInsts) ); } |
|
993 |
index = i8; |
|
994 |
op += 8; |
|
995 |
} |
|
365 | 996 |
} |
997 |
#endif |
|
155 | 998 |
while (index++ < nIndex) { |
999 |
if (*op++ == el) { |
|
345 | 1000 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
155 | 1001 |
} |
1002 |
} |
|
345 | 1003 |
RETURN ( __MKSMALLINT(0) ); |
155 | 1004 |
} |
1 | 1005 |
} |
356 | 1006 |
%}. |
1007 |
^ super identityIndexOf:anElement startingAt:start |
|
1008 |
! |
|
1009 |
||
1010 |
identityIndexOf:anElement or:alternative |
|
1011 |
"search the array for anElement or alternative; |
|
1012 |
return the index of anElement if found, or the index of anAlternative, |
|
1013 |
if not found. If anAlternative is also not found, return 0. |
|
1014 |
This is a special interface for high-speed searching in an array |
|
1015 |
and at the same time searching for an empty slot. |
|
1016 |
Do not use this method for your application classes, since it is |
|
1017 |
not portable (i.e. other smalltalks do not offer this)" |
|
1018 |
||
1019 |
%{ /* NOCONTEXT */ |
|
1020 |
||
1021 |
REGISTER int index; |
|
1022 |
REGISTER OBJ o, el1, el2; |
|
1023 |
REGISTER OBJ *op; |
|
1024 |
REGISTER unsigned int nIndex; |
|
1025 |
int altIndex = 0; |
|
1026 |
int nInsts; |
|
1027 |
||
1028 |
index = 0; |
|
1029 |
nInsts = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
|
1030 |
index += nInsts; |
|
1031 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1032 |
el1 = anElement; el2 = alternative; |
|
1033 |
op = & (_InstPtr(self)->i_instvars[index]); |
|
1034 |
while (index++ < nIndex) { |
|
1035 |
if ((o = *op++) == el1) { |
|
1036 |
RETURN ( __MKSMALLINT(index - nInsts) ); |
|
1037 |
} |
|
1038 |
if (o == el2) { |
|
1039 |
if (altIndex == 0) { |
|
1040 |
altIndex = index; |
|
1041 |
} |
|
1042 |
} |
|
1043 |
} |
|
1044 |
RETURN ( __MKSMALLINT(altIndex) ); |
|
1 | 1045 |
%} |
356 | 1046 |
|
1047 |
" |
|
1048 |
#(1 2 3 4 5 6 7 8 9) identityIndexOf:3 or:5 |
|
1049 |
#(1 2 0 4 5 6 7 8 9) identityIndexOf:3 or:5 |
|
1050 |
#(1 2 0 4 5 6 7 3 9) identityIndexOf:3 or:5 |
|
1051 |
#(1 2 3 4 5 nil 7 3 9) identityIndexOf:3 or:nil |
|
369 | 1052 |
#(1 2 nil 4 5 6 7 3 9) identityIndexOf:3 or:nil |
356 | 1053 |
#(1 2 nil 4 5 6 7 8 9) identityIndexOf:3 or:nil |
369 | 1054 |
#() identityIndexOf:3 or:nil |
356 | 1055 |
#(1 2) identityIndexOf:3 or:nil |
1056 |
" |
|
1 | 1057 |
! ! |
1058 |
||
11 | 1059 |
!Array methodsFor:'printing & storing'! |
1060 |
||
77 | 1061 |
displayString |
1062 |
"return a printed representation of the receiver for displaying" |
|
1063 |
||
1064 |
|s| |
|
1065 |
||
275 | 1066 |
(self isLiteral) ifTrue:[ |
155 | 1067 |
s := WriteStream on:String new. |
1068 |
s nextPutAll:'#('. |
|
1069 |
self do:[:element | s nextPutAll:element displayString. s space]. |
|
1070 |
s nextPutAll:')'. |
|
1071 |
^ s contents |
|
77 | 1072 |
]. |
1073 |
^ super displayString |
|
1074 |
! |
|
1075 |
||
11 | 1076 |
storeOn:aStream |
47 | 1077 |
"append a printed representation of the receiver to aStream, |
1078 |
which allows reconstructing it via readFrom:. |
|
281 | 1079 |
Redefined to output a somewhat more user friendly string." |
47 | 1080 |
|
11 | 1081 |
self isLiteral ifTrue:[ |
155 | 1082 |
aStream nextPutAll:'#('. |
1083 |
self do:[:element | element storeOn:aStream. aStream space]. |
|
1084 |
aStream nextPutAll:')' |
|
11 | 1085 |
] ifFalse:[ |
155 | 1086 |
super storeOn:aStream |
11 | 1087 |
] |
281 | 1088 |
|
1089 |
" |
|
1090 |
#(1 2 $a 'hello') storeString |
|
1091 |
" |
|
11 | 1092 |
! ! |
1093 |
||
216 | 1094 |
!Array methodsFor:'enumerating'! |
1 | 1095 |
|
1096 |
do:aBlock |
|
1097 |
"evaluate the argument, aBlock for each element in the collection. |
|
1098 |
- reimplemented for speed" |
|
1099 |
||
302 | 1100 |
|home| |
1 | 1101 |
%{ |
1102 |
REGISTER OBJFUNC codeVal; |
|
1103 |
REGISTER int index; |
|
92 | 1104 |
unsigned int nIndex; |
77 | 1105 |
extern OBJ Block; |
1 | 1106 |
static struct inlineCache val = _ILC1; |
2 | 1107 |
REGISTER OBJ rHome; |
1 | 1108 |
|
328 | 1109 |
index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
1110 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
155 | 1111 |
if (__isBlockLike(aBlock) |
1 | 1112 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
345 | 1113 |
&& (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
11 | 1114 |
#ifdef NEW_BLOCK_CALL |
155 | 1115 |
for (; index < nIndex; index++) { |
421 | 1116 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
11 | 1117 |
|
155 | 1118 |
(*codeVal)(aBlock, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1119 |
} |
|
11 | 1120 |
#else |
155 | 1121 |
home = _BlockInstPtr(aBlock)->b_home; |
1122 |
rHome = home; |
|
325 | 1123 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
155 | 1124 |
/* |
1125 |
* home will not move - keep in a fast register |
|
1126 |
*/ |
|
388 | 1127 |
#if defined(UNROLL_LOOPS) |
370 | 1128 |
{ |
1129 |
int i4; |
|
1130 |
||
379 | 1131 |
while ((i4 = index+4) < nIndex) { |
421 | 1132 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
370 | 1133 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index]); |
421 | 1134 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
370 | 1135 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index+1]); |
421 | 1136 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
370 | 1137 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index+2]); |
421 | 1138 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
370 | 1139 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index+3]); |
1140 |
index = i4; |
|
1141 |
} |
|
1142 |
} |
|
1143 |
#endif |
|
155 | 1144 |
for (; index < nIndex; index++) { |
421 | 1145 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
1 | 1146 |
|
155 | 1147 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1148 |
} |
|
1149 |
} else { |
|
1150 |
for (; index < nIndex; index++) { |
|
421 | 1151 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
2 | 1152 |
|
155 | 1153 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1154 |
} |
|
1155 |
} |
|
11 | 1156 |
#endif |
1 | 1157 |
} else { |
155 | 1158 |
for (; index < nIndex; index++) { |
421 | 1159 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
1 | 1160 |
|
155 | 1161 |
(*val.ilc_func)(aBlock, |
1162 |
@symbol(value:), |
|
1163 |
CON_COMMA nil, &val, |
|
1164 |
_InstPtr(self)->i_instvars[index]); |
|
1165 |
} |
|
1 | 1166 |
} |
1167 |
%} |
|
1168 |
. |
|
1169 |
^ self |
|
1170 |
! |
|
1171 |
||
219 | 1172 |
keysAndValuesDo:aBlock |
1173 |
"evaluate the argument, aBlock for each element in the collection. |
|
1174 |
Pass both index and element to the block. |
|
1175 |
- reimplemented for speed" |
|
1176 |
||
1177 |
|home| |
|
1178 |
%{ |
|
1179 |
REGISTER OBJFUNC codeVal; |
|
1180 |
REGISTER int index; |
|
1181 |
unsigned int nIndex; |
|
1182 |
extern OBJ Block; |
|
1183 |
static struct inlineCache val2 = _ILC2; |
|
1184 |
REGISTER OBJ rHome; |
|
1185 |
||
328 | 1186 |
index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
1187 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
219 | 1188 |
if (__isBlockLike(aBlock) |
1189 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
|
345 | 1190 |
&& (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(2))) { |
219 | 1191 |
#ifdef NEW_BLOCK_CALL |
1192 |
for (; index < nIndex; index++) { |
|
421 | 1193 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
219 | 1194 |
|
345 | 1195 |
(*codeVal)(aBlock, CON_COMMA __MKSMALLINT(index+1), |
219 | 1196 |
_InstPtr(self)->i_instvars[index]); |
1197 |
} |
|
1198 |
#else |
|
1199 |
home = _BlockInstPtr(aBlock)->b_home; |
|
1200 |
rHome = home; |
|
325 | 1201 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
219 | 1202 |
/* |
1203 |
* home will not move - keep in a fast register |
|
1204 |
*/ |
|
370 | 1205 |
while (index < nIndex) { |
421 | 1206 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
219 | 1207 |
|
370 | 1208 |
index++; |
1209 |
(*codeVal)(rHome, CON_COMMA __MKSMALLINT(index), |
|
1210 |
_InstPtr(self)->i_instvars[index-1]); |
|
219 | 1211 |
} |
1212 |
} else { |
|
370 | 1213 |
while (index < nIndex) { |
421 | 1214 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
219 | 1215 |
|
370 | 1216 |
index++; |
1217 |
(*codeVal)(home, CON_COMMA __MKSMALLINT(index), |
|
1218 |
_InstPtr(self)->i_instvars[index-1]); |
|
219 | 1219 |
} |
1220 |
} |
|
1221 |
#endif |
|
1222 |
} else { |
|
370 | 1223 |
while (index < nIndex) { |
421 | 1224 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
219 | 1225 |
|
370 | 1226 |
index++; |
287 | 1227 |
(*val2.ilc_func)(aBlock, |
219 | 1228 |
@symbol(value:value:), |
1229 |
CON_COMMA nil, &val2, |
|
370 | 1230 |
__MKSMALLINT(index), |
1231 |
_InstPtr(self)->i_instvars[index-1]); |
|
219 | 1232 |
} |
1233 |
} |
|
1234 |
%} |
|
1235 |
. |
|
1236 |
^ self |
|
1237 |
! |
|
1238 |
||
1 | 1239 |
reverseDo:aBlock |
1240 |
"evaluate the argument, aBlock for each element in the collection in reverse order. |
|
1241 |
- reimplemented for speed" |
|
1242 |
||
302 | 1243 |
|home| |
1 | 1244 |
%{ |
1245 |
REGISTER OBJFUNC codeVal; |
|
1246 |
REGISTER int index; |
|
92 | 1247 |
unsigned int nIndex; |
1248 |
int endIndex; |
|
77 | 1249 |
extern OBJ Block; |
1 | 1250 |
static struct inlineCache val = _ILC1; |
1251 |
||
328 | 1252 |
endIndex = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
421 | 1253 |
nIndex = __arraySize(self); |
1254 |
||
155 | 1255 |
if (__isBlockLike(aBlock) |
1 | 1256 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
345 | 1257 |
&& (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
11 | 1258 |
#ifdef NEW_BLOCK_CALL |
155 | 1259 |
for (index=nIndex-1; index >= endIndex; index--) { |
421 | 1260 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1261 |
(*codeVal)(aBlock, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1262 |
} |
|
11 | 1263 |
#else |
155 | 1264 |
home = _BlockInstPtr(aBlock)->b_home; |
1265 |
for (index=nIndex-1; index >= endIndex; index--) { |
|
421 | 1266 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1267 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1268 |
} |
|
11 | 1269 |
#endif |
1 | 1270 |
} else { |
421 | 1271 |
for (index=nIndex-1; index >= endIndex; index--) { |
1272 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
|
155 | 1273 |
(*val.ilc_func)(aBlock, |
1274 |
@symbol(value:), |
|
1275 |
CON_COMMA nil, &val, |
|
1276 |
_InstPtr(self)->i_instvars[index]); |
|
1277 |
} |
|
1 | 1278 |
} |
421 | 1279 |
%}. |
1 | 1280 |
^ self |
1281 |
! |
|
1282 |
||
1283 |
from:start to:stop do:aBlock |
|
1284 |
"evaluate the argument, aBlock for the elements starting at index start |
|
1285 |
up to (and including) stop in the collection. |
|
1286 |
- reimplemented for speed" |
|
1287 |
||
302 | 1288 |
|home| |
1 | 1289 |
%{ |
1290 |
REGISTER OBJFUNC codeVal; |
|
1291 |
REGISTER int index; |
|
2 | 1292 |
REGISTER OBJ rHome; |
1 | 1293 |
int nIndex, nInsts; |
77 | 1294 |
extern OBJ Block; |
1 | 1295 |
static struct inlineCache val = _ILC1; |
1296 |
int indexLow, indexHigh; |
|
1297 |
||
249 | 1298 |
if (__bothSmallInteger(start, stop)) { |
155 | 1299 |
indexLow = _intVal(start); |
1300 |
if (indexLow > 0) { |
|
1301 |
indexHigh = _intVal(stop); |
|
328 | 1302 |
if (__qClass(self) != Array) { |
1303 |
nInsts = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
|
155 | 1304 |
indexLow += nInsts; |
1305 |
indexHigh += nInsts; |
|
1306 |
} |
|
328 | 1307 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
155 | 1308 |
if (indexHigh <= nIndex) { |
1309 |
indexLow--; |
|
1310 |
indexHigh--; |
|
1311 |
if (__isBlockLike(aBlock) |
|
1312 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
|
345 | 1313 |
&& (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
11 | 1314 |
#ifdef NEW_BLOCK_CALL |
155 | 1315 |
for (index=indexLow; index <= indexHigh; index++) { |
421 | 1316 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1317 |
(*codeVal)(aBlock, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1318 |
} |
|
11 | 1319 |
#else |
155 | 1320 |
home = _BlockInstPtr(aBlock)->b_home; |
1321 |
rHome = home; |
|
325 | 1322 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
370 | 1323 |
index = indexLow; |
388 | 1324 |
#if defined(UNROLL_LOOPS) |
379 | 1325 |
{ |
1326 |
int i4; |
|
370 | 1327 |
|
379 | 1328 |
while ((i4 = index+4) <= indexHigh) { |
421 | 1329 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
379 | 1330 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index]); |
421 | 1331 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
379 | 1332 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index+1]); |
421 | 1333 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
379 | 1334 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index+2]); |
421 | 1335 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
379 | 1336 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index+3]); |
370 | 1337 |
index = i4; |
1338 |
} |
|
1339 |
} |
|
1340 |
#endif |
|
1341 |
for (; index <= indexHigh; index++) { |
|
421 | 1342 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1343 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1344 |
} |
|
1345 |
} else { |
|
1346 |
for (index=indexLow; index <= indexHigh; index++) { |
|
421 | 1347 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1348 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1349 |
} |
|
1350 |
} |
|
11 | 1351 |
#endif |
155 | 1352 |
} else { |
1353 |
for (index=indexLow; index <= indexHigh; index++) { |
|
421 | 1354 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1355 |
(*val.ilc_func) (aBlock, |
1356 |
@symbol(value:), |
|
1357 |
CON_COMMA nil, &val, |
|
302 | 1358 |
_InstPtr(self)->i_instvars[index]); |
155 | 1359 |
} |
1360 |
} |
|
1361 |
} |
|
1362 |
RETURN ( self ); |
|
1363 |
} |
|
1 | 1364 |
} |
1365 |
%} |
|
1366 |
. |
|
1367 |
^ super from:start to:stop do:aBlock |
|
1368 |
! |
|
1369 |
||
42 | 1370 |
from:start to:stop reverseDo:aBlock |
1371 |
"evaluate the argument, aBlock for the elements starting at index start |
|
1372 |
up to (and including) stop in the collection. Step in reverse order. |
|
1373 |
- reimplemented for speed" |
|
1374 |
||
302 | 1375 |
|home| |
42 | 1376 |
%{ |
1377 |
REGISTER OBJFUNC codeVal; |
|
1378 |
REGISTER int index; |
|
1379 |
REGISTER OBJ rHome; |
|
1380 |
int nIndex, nInsts; |
|
77 | 1381 |
extern OBJ Block; |
42 | 1382 |
static struct inlineCache val = _ILC1; |
1383 |
int indexLow, indexHigh; |
|
1384 |
||
249 | 1385 |
if (__bothSmallInteger(start, stop)) { |
155 | 1386 |
indexLow = _intVal(start); |
1387 |
if (indexLow > 0) { |
|
1388 |
indexHigh = _intVal(stop); |
|
328 | 1389 |
if (__qClass(self) != Array) { |
1390 |
nInsts = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
|
155 | 1391 |
indexLow += nInsts; |
1392 |
indexHigh += nInsts; |
|
1393 |
} |
|
328 | 1394 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
155 | 1395 |
if (indexHigh <= nIndex) { |
1396 |
indexLow--; |
|
1397 |
indexHigh--; |
|
1398 |
if (__isBlockLike(aBlock) |
|
1399 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
|
345 | 1400 |
&& (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
42 | 1401 |
#ifdef NEW_BLOCK_CALL |
155 | 1402 |
for (index=indexHigh; index >= indexLow; index--) { |
421 | 1403 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1404 |
(*codeVal)(aBlock, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1405 |
} |
|
42 | 1406 |
#else |
155 | 1407 |
home = _BlockInstPtr(aBlock)->b_home; |
1408 |
rHome = home; |
|
325 | 1409 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
155 | 1410 |
for (index=indexHigh; index >= indexLow; index--) { |
421 | 1411 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1412 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1413 |
} |
|
1414 |
} else { |
|
1415 |
for (index=indexHigh; index >= indexLow; index--) { |
|
421 | 1416 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1417 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]); |
1418 |
} |
|
1419 |
} |
|
42 | 1420 |
#endif |
155 | 1421 |
} else { |
1422 |
for (index=indexHigh; index >= indexLow; index--) { |
|
421 | 1423 |
if (InterruptPending != nil) __interruptL(@line COMMA_CON); |
155 | 1424 |
(*val.ilc_func) (aBlock, |
1425 |
@symbol(value:), |
|
1426 |
CON_COMMA nil, &val, |
|
302 | 1427 |
_InstPtr(self)->i_instvars[index]); |
155 | 1428 |
} |
1429 |
} |
|
1430 |
} |
|
1431 |
RETURN ( self ); |
|
1432 |
} |
|
42 | 1433 |
} |
1434 |
%} |
|
1435 |
. |
|
1436 |
^ super from:start to:stop reverseDo:aBlock |
|
1437 |
! |
|
1438 |
||
1 | 1439 |
nonNilElementsDo:aBlock |
1440 |
"evaluate the argument, aBlock for each non-nil element" |
|
1441 |
||
302 | 1442 |
|home| |
1 | 1443 |
%{ |
1444 |
REGISTER OBJFUNC codeVal; |
|
1445 |
REGISTER int index; |
|
1446 |
int nIndex; |
|
77 | 1447 |
extern OBJ Block; |
1 | 1448 |
static struct inlineCache val = _ILC1; |
302 | 1449 |
REGISTER OBJ rHome; |
1450 |
REGISTER OBJ element; |
|
1 | 1451 |
|
328 | 1452 |
index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars); |
1453 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
155 | 1454 |
if (__isBlockLike(aBlock) |
1 | 1455 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
345 | 1456 |
&& (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
11 | 1457 |
#ifdef NEW_BLOCK_CALL |
155 | 1458 |
for (; index < nIndex; index++) { |
421 | 1459 |
if (InterruptPending != nil) __interruptL(CONARG); |
11 | 1460 |
|
155 | 1461 |
element = _InstPtr(self)->i_instvars[index]; |
1462 |
if (element != nil) |
|
1463 |
(*codeVal)(aBlock, CON_COMMA element); |
|
1464 |
} |
|
11 | 1465 |
#else |
155 | 1466 |
home = _BlockInstPtr(aBlock)->b_home; |
328 | 1467 |
rHome = home; |
1468 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
|
1469 |
/* |
|
1470 |
* home will not move - keep in in a register |
|
1471 |
*/ |
|
302 | 1472 |
for (; index < nIndex; index++) { |
421 | 1473 |
if (InterruptPending != nil) __interruptL(CONARG); |
1 | 1474 |
|
328 | 1475 |
element = _InstPtr(self)->i_instvars[index]; |
1476 |
if (element != nil) |
|
370 | 1477 |
(*codeVal)(rHome, CON_COMMA element); |
302 | 1478 |
} |
1479 |
} else { |
|
1480 |
for (; index < nIndex; index++) { |
|
421 | 1481 |
if (InterruptPending != nil) __interruptL(@line CONARG); |
302 | 1482 |
|
328 | 1483 |
element = _InstPtr(self)->i_instvars[index]; |
1484 |
if (element != nil) |
|
302 | 1485 |
(*codeVal)(home, CON_COMMA element); |
1486 |
} |
|
155 | 1487 |
} |
11 | 1488 |
#endif |
1 | 1489 |
} else { |
155 | 1490 |
for (; index < nIndex; index++) { |
421 | 1491 |
if (InterruptPending != nil) __interruptL(@line CONARG); |
1 | 1492 |
|
155 | 1493 |
element = _InstPtr(self)->i_instvars[index]; |
1494 |
if (element != nil) |
|
1495 |
(*val.ilc_func)(aBlock, |
|
1496 |
@symbol(value:), |
|
1497 |
CON_COMMA nil, &val, |
|
1498 |
element); |
|
1499 |
} |
|
1 | 1500 |
} |
1501 |
%} |
|
1502 |
. |
|
1503 |
^ self |
|
11 | 1504 |
! |
1505 |
||
328 | 1506 |
traverse:aBlock |
1507 |
"Evaluate aBlock for every element that is not an Array, |
|
1508 |
and traverse Arrays. |
|
1509 |
Implemented here to support better search for selectors in |
|
1510 |
literal arrays - might be a good idea to move it up in the collection |
|
1511 |
hierarchy, since this may be a useful method for other collections |
|
1512 |
as well." |
|
1513 |
||
1514 |
self do: [:el | |
|
370 | 1515 |
el isArray |
328 | 1516 |
ifTrue: [el traverse: aBlock] |
1517 |
ifFalse: [aBlock value: el]] |
|
1518 |
||
1519 |
" |
|
1520 |
example: flattening an Array: |
|
1521 |
||
1522 |
|s| |
|
1523 |
||
1524 |
s := WriteStream on:Array new. |
|
1525 |
#(1 2 (3 (4 5 (6 7) 8) 9 10) 11 (12 (13)) 14) traverse:[:el | s nextPut:el]. |
|
1526 |
s contents |
|
1527 |
" |
|
1528 |
! |
|
1529 |
||
11 | 1530 |
addAllTo:aCollection |
1531 |
"add all elements of the receiver to aCollection. |
|
1532 |
return aCollection." |
|
1533 |
||
1534 |
|stop "{ Class: SmallInteger }"| |
|
1535 |
||
1536 |
stop := self size. |
|
1537 |
1 to:stop do:[:idx | |
|
155 | 1538 |
aCollection add:(self at:idx) |
11 | 1539 |
]. |
1540 |
^ aCollection |
|
1 | 1541 |
! ! |