1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
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:''
|
|
17 |
category:'Collections-Indexed'
|
|
18 |
!
|
|
19 |
|
|
20 |
Array comment:'
|
|
21 |
|
5
|
22 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
Arrays store general objects; the size is fixed, so add/remove is not
|
|
26 |
allowed. Access to the elements is via an Integer index. Since Arrays
|
|
27 |
are used very often in the system, some methods have been tuned by
|
|
28 |
reimplementation as primitive.
|
|
29 |
|
10
|
30 |
$Header: /cvs/stx/stx/libbasic/Array.st,v 1.5 1993-11-08 02:28:44 claus Exp $
|
1
|
31 |
|
|
32 |
written spring 89 by claus
|
|
33 |
'!
|
|
34 |
|
3
|
35 |
!Array class methodsFor:'queries'!
|
|
36 |
|
|
37 |
isBuiltInClass
|
|
38 |
"this class is known by the run-time-system"
|
|
39 |
|
|
40 |
^ self == Array
|
|
41 |
! !
|
|
42 |
|
1
|
43 |
!Array methodsFor:'accessing'!
|
|
44 |
|
|
45 |
size
|
|
46 |
"return the number of indexed elements in the receiver"
|
|
47 |
|
|
48 |
%{ /* NOCONTEXT */
|
|
49 |
|
|
50 |
RETURN ( _MKSMALLINT(_arraySize(self) - _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars) ));
|
|
51 |
%}
|
|
52 |
!
|
|
53 |
|
|
54 |
at:index
|
|
55 |
"return the indexed instance variable with index, anInteger
|
|
56 |
- added here for speed"
|
|
57 |
|
|
58 |
%{ /* NOCONTEXT */
|
|
59 |
|
|
60 |
REGISTER int indx;
|
|
61 |
REGISTER int nIndex;
|
|
62 |
|
|
63 |
if (_isSmallInteger(index)) {
|
|
64 |
indx = _intVal(index) - 1;
|
2
|
65 |
if (indx >= 0) {
|
1
|
66 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
67 |
indx += _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
68 |
if (indx < nIndex) {
|
|
69 |
RETURN ( _InstPtr(self)->i_instvars[indx] );
|
|
70 |
}
|
|
71 |
}
|
|
72 |
}
|
|
73 |
%}
|
|
74 |
.
|
|
75 |
^ super at:index
|
|
76 |
!
|
|
77 |
|
|
78 |
at:index put:anObject
|
|
79 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger.
|
|
80 |
- added here for speed"
|
|
81 |
|
|
82 |
%{ /* NOCONTEXT */
|
|
83 |
|
|
84 |
REGISTER int indx;
|
|
85 |
REGISTER int nIndex;
|
|
86 |
|
|
87 |
if (_isSmallInteger(index)) {
|
|
88 |
indx = _intVal(index) - 1;
|
|
89 |
if (indx >= 0) {
|
|
90 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
91 |
indx += _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
92 |
if (indx < nIndex) {
|
|
93 |
_InstPtr(self)->i_instvars[indx] = anObject;
|
|
94 |
__STORE(self, anObject);
|
|
95 |
RETURN ( anObject );
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
99 |
%}
|
|
100 |
.
|
|
101 |
^ super at:index put:anObject
|
|
102 |
! !
|
|
103 |
|
|
104 |
!Array methodsFor:'copying'!
|
|
105 |
|
|
106 |
copyWith:something
|
|
107 |
"reimplemented for speed if receiver is an Array"
|
|
108 |
%{
|
|
109 |
OBJ nObj;
|
|
110 |
int mySize;
|
|
111 |
int i, nIndex;
|
|
112 |
OBJ *op;
|
|
113 |
extern int newSpace;
|
|
114 |
|
|
115 |
if (_qClass(self) == Array) {
|
|
116 |
mySize = _qSize(self);
|
|
117 |
_qAlignedNew(nObj, mySize + sizeof(OBJ), __context);
|
|
118 |
_InstPtr(nObj)->o_class = Array;
|
|
119 |
|
2
|
120 |
nIndex = (mySize - OHDR_SIZE) / sizeof(OBJ);
|
10
|
121 |
/* sorry: must take care of stores ... */
|
|
122 |
op = _ArrayInstPtr(self)->a_element;
|
|
123 |
for (i=0; i<nIndex; i++) {
|
|
124 |
_ArrayInstPtr(nObj)->a_element[i] = *op;
|
|
125 |
__STORE(nObj, *op);
|
|
126 |
op++;
|
2
|
127 |
}
|
10
|
128 |
_ArrayInstPtr(nObj)->a_element[i] = something;
|
|
129 |
__STORE(nObj, something);
|
1
|
130 |
RETURN ( nObj );
|
|
131 |
}
|
|
132 |
%}
|
|
133 |
.
|
|
134 |
^ super copyWith:something
|
|
135 |
! !
|
|
136 |
|
|
137 |
!Array methodsFor:'filling & replacing'!
|
|
138 |
|
|
139 |
from:index1 to:index2 put:anObject
|
|
140 |
"reimplemented for speed if receiver is an Array"
|
|
141 |
|
|
142 |
%{ /* NOCONTEXT */
|
|
143 |
|
|
144 |
REGISTER int index;
|
|
145 |
int nIndex;
|
|
146 |
int endIndex;
|
|
147 |
REGISTER OBJ *dst;
|
|
148 |
|
|
149 |
if ((_qClass(self) == Array)
|
|
150 |
&& _isSmallInteger(index1)
|
|
151 |
&& _isSmallInteger(index2)) {
|
|
152 |
index = _intVal(index1) - 1;
|
|
153 |
if (index >= 0) {
|
|
154 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
155 |
endIndex = _intVal(index2) - 1;
|
|
156 |
if (endIndex < nIndex) {
|
|
157 |
dst = &(_InstPtr(self)->i_instvars[index]);
|
|
158 |
#ifdef memset4
|
|
159 |
memset4(dst, anObject, (endIndex-index+1));
|
|
160 |
__STORE(self, anObject);
|
|
161 |
#else
|
|
162 |
if ((INT)anObject == 0) {
|
|
163 |
memset(dst, 0, (endIndex-index+1) * sizeof(OBJ));
|
|
164 |
} else {
|
|
165 |
for (; index <= endIndex; index++) {
|
|
166 |
*dst++ = anObject;
|
|
167 |
}
|
|
168 |
__STORE(self, anObject);
|
|
169 |
}
|
|
170 |
#endif
|
|
171 |
RETURN ( self );
|
|
172 |
}
|
|
173 |
}
|
|
174 |
}
|
|
175 |
%}
|
|
176 |
.
|
|
177 |
^ super from:index1 to:index2 put:anObject
|
|
178 |
!
|
|
179 |
|
|
180 |
replaceFrom:start to:stop with:aCollection startingAt:repStart
|
|
181 |
"reimplemented for speed if both receiver and aCollection are Arrays"
|
|
182 |
|
|
183 |
%{ /* NOCONTEXT */
|
|
184 |
|
|
185 |
int nIndex, repNIndex;
|
|
186 |
int startIndex, stopIndex;
|
|
187 |
REGISTER OBJ *src;
|
|
188 |
REGISTER OBJ *dst;
|
|
189 |
int repStopIndex;
|
|
190 |
REGISTER int repStartIndex;
|
|
191 |
REGISTER OBJ t;
|
|
192 |
REGISTER int count;
|
|
193 |
extern int newSpace;
|
|
194 |
|
|
195 |
if ((_qClass(self) == Array)
|
|
196 |
&& (_Class(aCollection) == Array)
|
|
197 |
&& _isSmallInteger(start)
|
|
198 |
&& _isSmallInteger(stop)
|
|
199 |
&& _isSmallInteger(repStart)) {
|
|
200 |
startIndex = _intVal(start) - 1;
|
|
201 |
if (startIndex >= 0) {
|
|
202 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
203 |
stopIndex = _intVal(stop) - 1;
|
|
204 |
count = stopIndex - startIndex + 1;
|
|
205 |
if ((count > 0) && (stopIndex < nIndex)) {
|
|
206 |
repStartIndex = _intVal(repStart) - 1;
|
|
207 |
if (repStartIndex >= 0) {
|
|
208 |
repNIndex = (_qSize(aCollection) - OHDR_SIZE) / sizeof(OBJ);
|
|
209 |
repStopIndex = repStartIndex + (stopIndex - startIndex);
|
|
210 |
if (repStopIndex < repNIndex) {
|
|
211 |
src = &(_InstPtr(aCollection)->i_instvars[repStartIndex]);
|
|
212 |
dst = &(_InstPtr(self)->i_instvars[startIndex]);
|
|
213 |
if (aCollection == self) {
|
|
214 |
/* no need to check stores */
|
|
215 |
/* take care of overlapping copy */
|
|
216 |
if (src < dst) {
|
|
217 |
/* must do a reverse copy */
|
|
218 |
src += count;
|
|
219 |
dst += count;
|
|
220 |
while (count-- > 0) {
|
|
221 |
*--dst = *--src;
|
|
222 |
}
|
|
223 |
RETURN ( self );
|
|
224 |
}
|
|
225 |
#ifdef bcopy4
|
2
|
226 |
bcopy4(src, dst, count);
|
1
|
227 |
#else
|
|
228 |
# ifdef FAST_MEMCPY
|
|
229 |
bcopy(src, dst, count*sizeof(OBJ));
|
|
230 |
# else
|
|
231 |
while (count--) {
|
|
232 |
*dst++ = *src++;
|
|
233 |
}
|
|
234 |
# endif
|
|
235 |
#endif
|
|
236 |
} else {
|
10
|
237 |
while (count-- > 0) {
|
|
238 |
t = *src++;
|
|
239 |
*dst++ = t;
|
|
240 |
__STORE(self, t);
|
1
|
241 |
}
|
|
242 |
}
|
|
243 |
RETURN ( self );
|
|
244 |
}
|
|
245 |
}
|
|
246 |
}
|
|
247 |
}
|
|
248 |
}
|
|
249 |
%}
|
|
250 |
.
|
|
251 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
|
|
252 |
! !
|
|
253 |
|
|
254 |
!Array methodsFor:'testing'!
|
|
255 |
|
|
256 |
includes:anObject
|
|
257 |
"return true, if the argument, anObject is contained in the array
|
|
258 |
- reimplemented for speed"
|
|
259 |
|
|
260 |
|element|
|
|
261 |
|
|
262 |
%{ /* NOCONTEXT */
|
|
263 |
|
|
264 |
REGISTER int index;
|
|
265 |
REGISTER OBJ o;
|
|
266 |
int nIndex;
|
|
267 |
|
|
268 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
269 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
270 |
|
|
271 |
/* quick check using == */
|
|
272 |
o = anObject;
|
|
273 |
while (index < nIndex) {
|
|
274 |
if (_InstPtr(self)->i_instvars[index++] == o) {
|
|
275 |
RETURN ( true );
|
2
|
276 |
}
|
1
|
277 |
}
|
|
278 |
if (o == nil) {
|
2
|
279 |
RETURN ( false );
|
1
|
280 |
}
|
|
281 |
%}
|
|
282 |
.
|
|
283 |
%{
|
|
284 |
REGISTER int index;
|
|
285 |
int nIndex;
|
|
286 |
extern OBJ __eq;
|
|
287 |
static struct inlineCache eq = _ILC1;
|
|
288 |
|
|
289 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
290 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
291 |
|
|
292 |
/* slow check using = */
|
|
293 |
|
|
294 |
while (index < nIndex) {
|
|
295 |
element = _InstPtr(self)->i_instvars[index++];
|
2
|
296 |
if (element != nil) {
|
10
|
297 |
if ((*eq.ilc_func)(anObject,__eq, CON_COMMA nil,&eq,element)==true) {
|
1
|
298 |
RETURN ( true );
|
2
|
299 |
}
|
|
300 |
}
|
1
|
301 |
}
|
|
302 |
%}
|
|
303 |
.
|
|
304 |
^ false
|
|
305 |
!
|
|
306 |
|
|
307 |
indexOf:anElement startingAt:start
|
|
308 |
"search the array for anElement; return index if found, 0 otherwise
|
|
309 |
- reimplemented for speed"
|
|
310 |
|
|
311 |
|element|
|
|
312 |
%{
|
|
313 |
REGISTER int index;
|
|
314 |
int nIndex, nInsts;
|
|
315 |
extern OBJ __eq;
|
|
316 |
static struct inlineCache eq = _ILC1;
|
|
317 |
|
|
318 |
if (_isSmallInteger(start)) {
|
|
319 |
index = _intVal(start) - 1;
|
|
320 |
if (index >= 0) {
|
|
321 |
nInsts = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
322 |
index += nInsts;
|
|
323 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
2
|
324 |
if (anElement != nil) {
|
1
|
325 |
while (index < nIndex) {
|
|
326 |
element = _InstPtr(self)->i_instvars[index++];
|
2
|
327 |
if (element != nil) {
|
1
|
328 |
if ((element == anElement)
|
10
|
329 |
|| ((*eq.ilc_func)(anElement,__eq, CON_COMMA nil,&eq,element) == true)) {
|
1
|
330 |
RETURN ( _MKSMALLINT(index - nInsts) );
|
|
331 |
}
|
|
332 |
}
|
|
333 |
}
|
2
|
334 |
} else {
|
|
335 |
/* search for nil */
|
1
|
336 |
while (index < nIndex) {
|
|
337 |
if (_InstPtr(self)->i_instvars[index++] == nil) {
|
|
338 |
RETURN ( _MKSMALLINT(index - nInsts) );
|
|
339 |
}
|
|
340 |
}
|
|
341 |
}
|
|
342 |
}
|
|
343 |
}
|
|
344 |
%}
|
|
345 |
.
|
|
346 |
^ 0
|
|
347 |
!
|
|
348 |
|
|
349 |
identityIndexOf:anElement startingAt:start
|
|
350 |
"search the array for anElement; return index if found, 0 otherwise
|
|
351 |
- reimplemented for speed"
|
|
352 |
|
|
353 |
%{ /* NOCONTEXT */
|
|
354 |
|
|
355 |
REGISTER int index;
|
|
356 |
REGISTER OBJ el;
|
|
357 |
REGISTER OBJ *op;
|
|
358 |
REGISTER int nIndex;
|
|
359 |
int nInsts;
|
|
360 |
|
|
361 |
if (_isSmallInteger(start)) {
|
|
362 |
index = _intVal(start) - 1;
|
|
363 |
if (index >= 0) {
|
|
364 |
nInsts = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
365 |
index += nInsts;
|
|
366 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
367 |
el = anElement;
|
|
368 |
op = & (_InstPtr(self)->i_instvars[index]);
|
|
369 |
while (index++ < nIndex) {
|
|
370 |
if (*op++ == el) {
|
|
371 |
RETURN ( _MKSMALLINT(index - nInsts) );
|
|
372 |
}
|
|
373 |
}
|
2
|
374 |
RETURN ( _MKSMALLINT(0) );
|
1
|
375 |
}
|
|
376 |
}
|
|
377 |
%}
|
|
378 |
.
|
|
379 |
^ super identityIndexOf:anElement startingAt:start
|
|
380 |
! !
|
|
381 |
|
|
382 |
!Array methodsFor:'enumeration'!
|
|
383 |
|
|
384 |
do:aBlock
|
|
385 |
"evaluate the argument, aBlock for each element in the collection.
|
|
386 |
- reimplemented for speed"
|
|
387 |
|
|
388 |
|home element|
|
|
389 |
%{
|
|
390 |
REGISTER OBJFUNC codeVal;
|
|
391 |
REGISTER int index;
|
|
392 |
int nIndex;
|
|
393 |
extern OBJ _value_, Block;
|
|
394 |
static struct inlineCache val = _ILC1;
|
2
|
395 |
REGISTER OBJ rHome;
|
1
|
396 |
|
|
397 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
398 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
2
|
399 |
if (__isBlock(aBlock)
|
1
|
400 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
401 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
402 |
home = _BlockInstPtr(aBlock)->b_home;
|
2
|
403 |
rHome = home;
|
|
404 |
if ((rHome == nil) || (_qSpace(rHome) >= STACKSPACE)) {
|
|
405 |
/*
|
|
406 |
* home will not move - keep in a fast register
|
|
407 |
*/
|
|
408 |
for (; index < nIndex; index++) {
|
|
409 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
1
|
410 |
|
2
|
411 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index]);
|
|
412 |
}
|
|
413 |
} else {
|
|
414 |
for (; index < nIndex; index++) {
|
|
415 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
416 |
|
|
417 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]);
|
|
418 |
}
|
1
|
419 |
}
|
|
420 |
} else {
|
|
421 |
for (; index < nIndex; index++) {
|
2
|
422 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
1
|
423 |
|
2
|
424 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val,
|
|
425 |
_InstPtr(self)->i_instvars[index]);
|
1
|
426 |
}
|
|
427 |
}
|
|
428 |
%}
|
|
429 |
.
|
|
430 |
^ self
|
|
431 |
!
|
|
432 |
|
|
433 |
reverseDo:aBlock
|
|
434 |
"evaluate the argument, aBlock for each element in the collection in reverse order.
|
|
435 |
- reimplemented for speed"
|
|
436 |
|
|
437 |
|home element|
|
|
438 |
%{
|
|
439 |
REGISTER OBJFUNC codeVal;
|
|
440 |
REGISTER int index;
|
|
441 |
int nIndex, endIndex;
|
|
442 |
extern OBJ _value_, Block;
|
|
443 |
static struct inlineCache val = _ILC1;
|
|
444 |
|
|
445 |
endIndex = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
446 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
2
|
447 |
if (__isBlock(aBlock)
|
1
|
448 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
449 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
450 |
home = _BlockInstPtr(aBlock)->b_home;
|
|
451 |
for (index=nIndex-1; index >= endIndex; index--) {
|
2
|
452 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
453 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]);
|
1
|
454 |
}
|
|
455 |
} else {
|
|
456 |
for (index=nIndex=1; index >= endIndex; index--) {
|
2
|
457 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
458 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val,
|
|
459 |
_InstPtr(self)->i_instvars[index]);
|
1
|
460 |
}
|
|
461 |
}
|
|
462 |
%}
|
|
463 |
.
|
|
464 |
^ self
|
|
465 |
!
|
|
466 |
|
|
467 |
from:start to:stop do:aBlock
|
|
468 |
"evaluate the argument, aBlock for the elements starting at index start
|
|
469 |
up to (and including) stop in the collection.
|
|
470 |
- reimplemented for speed"
|
|
471 |
|
|
472 |
|home element|
|
|
473 |
%{
|
|
474 |
REGISTER OBJFUNC codeVal;
|
|
475 |
REGISTER int index;
|
2
|
476 |
REGISTER OBJ rHome;
|
1
|
477 |
int nIndex, nInsts;
|
|
478 |
extern OBJ _value_, Block;
|
|
479 |
static struct inlineCache val = _ILC1;
|
|
480 |
int indexLow, indexHigh;
|
|
481 |
|
|
482 |
if (_isSmallInteger(start) && _isSmallInteger(stop)) {
|
|
483 |
indexLow = _intVal(start);
|
|
484 |
if (indexLow > 0) {
|
|
485 |
indexHigh = _intVal(stop);
|
2
|
486 |
if (_qClass(self) != Array) {
|
|
487 |
nInsts = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
488 |
indexLow += nInsts;
|
|
489 |
indexHigh += nInsts;
|
|
490 |
}
|
1
|
491 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
492 |
if (indexHigh <= nIndex) {
|
|
493 |
indexLow--;
|
|
494 |
indexHigh--;
|
2
|
495 |
if (__isBlock(aBlock)
|
1
|
496 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
497 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
498 |
home = _BlockInstPtr(aBlock)->b_home;
|
2
|
499 |
rHome = home;
|
|
500 |
if ((rHome == nil) || (_qSpace(rHome) >= STACKSPACE)) {
|
|
501 |
for (index=indexLow; index <= indexHigh; index++) {
|
|
502 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
503 |
(*codeVal)(rHome, CON_COMMA _InstPtr(self)->i_instvars[index]);
|
|
504 |
}
|
|
505 |
} else {
|
|
506 |
for (index=indexLow; index <= indexHigh; index++) {
|
|
507 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
508 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]);
|
|
509 |
}
|
|
510 |
}
|
1
|
511 |
} else {
|
|
512 |
for (index=indexLow; index <= indexHigh; index++) {
|
2
|
513 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
1
|
514 |
element = _InstPtr(self)->i_instvars[index];
|
2
|
515 |
(*val.ilc_func) (aBlock, _value_, CON_COMMA nil, &val, element);
|
1
|
516 |
}
|
|
517 |
}
|
|
518 |
RETURN ( self );
|
|
519 |
}
|
|
520 |
}
|
|
521 |
}
|
|
522 |
%}
|
|
523 |
.
|
|
524 |
^ super from:start to:stop do:aBlock
|
|
525 |
!
|
|
526 |
|
|
527 |
nonNilElementsDo:aBlock
|
|
528 |
"evaluate the argument, aBlock for each non-nil element"
|
|
529 |
|
|
530 |
|home element|
|
|
531 |
%{
|
|
532 |
REGISTER OBJFUNC codeVal;
|
|
533 |
REGISTER int index;
|
|
534 |
int nIndex;
|
|
535 |
extern OBJ _value_, Block;
|
|
536 |
static struct inlineCache val = _ILC1;
|
|
537 |
|
|
538 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
539 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
2
|
540 |
if (__isBlock(aBlock)
|
1
|
541 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
542 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
543 |
home = _BlockInstPtr(aBlock)->b_home;
|
|
544 |
for (; index < nIndex; index++) {
|
2
|
545 |
if (InterruptPending != nil) interrupt(CONARG);
|
1
|
546 |
|
|
547 |
element = _InstPtr(self)->i_instvars[index];
|
2
|
548 |
if (element != nil)
|
1
|
549 |
(*codeVal)(home, CON_COMMA element);
|
|
550 |
}
|
|
551 |
} else {
|
|
552 |
for (; index < nIndex; index++) {
|
2
|
553 |
if (InterruptPending != nil) interrupt(CONARG);
|
1
|
554 |
|
|
555 |
element = _InstPtr(self)->i_instvars[index];
|
2
|
556 |
if (element != nil)
|
1
|
557 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val, element);
|
|
558 |
}
|
|
559 |
}
|
|
560 |
%}
|
|
561 |
.
|
|
562 |
^ self
|
|
563 |
! !
|