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