1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-92 by Claus Gittinger
|
|
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 |
|
|
22 |
COPYRIGHT (c) 1989-92 by Claus Gittinger
|
|
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 |
|
|
30 |
%W% %E%
|
|
31 |
|
|
32 |
written spring 89 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!Array methodsFor:'resizing'!
|
|
36 |
|
|
37 |
grow:newSize
|
|
38 |
(newSize ~~ self size) ifTrue:[
|
|
39 |
self fixedSizeError
|
|
40 |
]
|
|
41 |
! !
|
|
42 |
|
|
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;
|
|
65 |
if (indx >= 0) {
|
|
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 |
|
|
120 |
nIndex = (mySize - OHDR_SIZE) / sizeof(OBJ);
|
|
121 |
/* created object is usually in newspace */
|
|
122 |
if (_qSpace(nObj) == newSpace) {
|
|
123 |
/* dont care for store */
|
|
124 |
#ifdef bcopy4
|
|
125 |
bcopy4(_ArrayInstPtr(self)->a_element, _ArrayInstPtr(nObj)->a_element, nIndex);
|
|
126 |
#else
|
|
127 |
bcopy(_ArrayInstPtr(self)->a_element, _ArrayInstPtr(nObj)->a_element, mySize - OHDR_SIZE);
|
|
128 |
#endif
|
|
129 |
_ArrayInstPtr(nObj)->a_element[nIndex] = something;
|
|
130 |
} else {
|
|
131 |
/* must take care of stores ... */
|
|
132 |
op = _ArrayInstPtr(self)->a_element;
|
|
133 |
for (i=0; i<nIndex; i++) {
|
|
134 |
_ArrayInstPtr(nObj)->a_element[i] = *op;
|
|
135 |
__STORE(nObj, *op);
|
|
136 |
op++;
|
|
137 |
}
|
|
138 |
_ArrayInstPtr(nObj)->a_element[i] = something;
|
|
139 |
__STORE(nObj, something);
|
|
140 |
}
|
|
141 |
RETURN ( nObj );
|
|
142 |
}
|
|
143 |
%}
|
|
144 |
.
|
|
145 |
^ super copyWith:something
|
|
146 |
! !
|
|
147 |
|
|
148 |
!Array methodsFor:'filling & replacing'!
|
|
149 |
|
|
150 |
from:index1 to:index2 put:anObject
|
|
151 |
"reimplemented for speed if receiver is an Array"
|
|
152 |
|
|
153 |
%{ /* NOCONTEXT */
|
|
154 |
|
|
155 |
REGISTER int index;
|
|
156 |
int nIndex;
|
|
157 |
int endIndex;
|
|
158 |
REGISTER OBJ *dst;
|
|
159 |
|
|
160 |
if ((_qClass(self) == Array)
|
|
161 |
&& _isSmallInteger(index1)
|
|
162 |
&& _isSmallInteger(index2)) {
|
|
163 |
index = _intVal(index1) - 1;
|
|
164 |
if (index >= 0) {
|
|
165 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
166 |
endIndex = _intVal(index2) - 1;
|
|
167 |
if (endIndex < nIndex) {
|
|
168 |
dst = &(_InstPtr(self)->i_instvars[index]);
|
|
169 |
#ifdef memset4
|
|
170 |
memset4(dst, anObject, (endIndex-index+1));
|
|
171 |
__STORE(self, anObject);
|
|
172 |
#else
|
|
173 |
if ((INT)anObject == 0) {
|
|
174 |
memset(dst, 0, (endIndex-index+1) * sizeof(OBJ));
|
|
175 |
} else {
|
|
176 |
for (; index <= endIndex; index++) {
|
|
177 |
*dst++ = anObject;
|
|
178 |
}
|
|
179 |
__STORE(self, anObject);
|
|
180 |
}
|
|
181 |
#endif
|
|
182 |
RETURN ( self );
|
|
183 |
}
|
|
184 |
}
|
|
185 |
}
|
|
186 |
%}
|
|
187 |
.
|
|
188 |
^ super from:index1 to:index2 put:anObject
|
|
189 |
!
|
|
190 |
|
|
191 |
replaceFrom:start to:stop with:aCollection startingAt:repStart
|
|
192 |
"reimplemented for speed if both receiver and aCollection are Arrays"
|
|
193 |
|
|
194 |
%{ /* NOCONTEXT */
|
|
195 |
|
|
196 |
int nIndex, repNIndex;
|
|
197 |
int startIndex, stopIndex;
|
|
198 |
REGISTER OBJ *src;
|
|
199 |
REGISTER OBJ *dst;
|
|
200 |
int repStopIndex;
|
|
201 |
REGISTER int repStartIndex;
|
|
202 |
REGISTER OBJ t;
|
|
203 |
REGISTER int count;
|
|
204 |
extern int newSpace;
|
|
205 |
|
|
206 |
if ((_qClass(self) == Array)
|
|
207 |
&& (_Class(aCollection) == Array)
|
|
208 |
&& _isSmallInteger(start)
|
|
209 |
&& _isSmallInteger(stop)
|
|
210 |
&& _isSmallInteger(repStart)) {
|
|
211 |
startIndex = _intVal(start) - 1;
|
|
212 |
if (startIndex >= 0) {
|
|
213 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
214 |
stopIndex = _intVal(stop) - 1;
|
|
215 |
count = stopIndex - startIndex + 1;
|
|
216 |
if ((count > 0) && (stopIndex < nIndex)) {
|
|
217 |
repStartIndex = _intVal(repStart) - 1;
|
|
218 |
if (repStartIndex >= 0) {
|
|
219 |
repNIndex = (_qSize(aCollection) - OHDR_SIZE) / sizeof(OBJ);
|
|
220 |
repStopIndex = repStartIndex + (stopIndex - startIndex);
|
|
221 |
if (repStopIndex < repNIndex) {
|
|
222 |
src = &(_InstPtr(aCollection)->i_instvars[repStartIndex]);
|
|
223 |
dst = &(_InstPtr(self)->i_instvars[startIndex]);
|
|
224 |
if (aCollection == self) {
|
|
225 |
/* no need to check stores */
|
|
226 |
/* take care of overlapping copy */
|
|
227 |
if (src < dst) {
|
|
228 |
/* must do a reverse copy */
|
|
229 |
src += count;
|
|
230 |
dst += count;
|
|
231 |
while (count-- > 0) {
|
|
232 |
*--dst = *--src;
|
|
233 |
}
|
|
234 |
RETURN ( self );
|
|
235 |
}
|
|
236 |
#ifdef bcopy4
|
|
237 |
bcopy4(src, dst, count);
|
|
238 |
#else
|
|
239 |
# ifdef FAST_MEMCPY
|
|
240 |
bcopy(src, dst, count*sizeof(OBJ));
|
|
241 |
# else
|
|
242 |
while (count >= 4) {
|
|
243 |
MOVE4LONGS(src, dst);
|
|
244 |
count -= 4;
|
|
245 |
}
|
|
246 |
while (count--) {
|
|
247 |
*dst++ = *src++;
|
|
248 |
}
|
|
249 |
# endif
|
|
250 |
#endif
|
|
251 |
} else {
|
|
252 |
/*
|
|
253 |
* no need for store-check, if dst is in newspace
|
|
254 |
*/
|
|
255 |
if (_qSpace(self) == newSpace) {
|
|
256 |
#ifdef bcopy4
|
|
257 |
bcopy4(src, dst, count);
|
|
258 |
#else
|
|
259 |
# ifdef FAST_MEMCPY
|
|
260 |
bcopy(src, dst, count*sizeof(OBJ));
|
|
261 |
# else
|
|
262 |
while (count >= 4) {
|
|
263 |
MOVE4LONGS(src, dst);
|
|
264 |
count -= 4;
|
|
265 |
}
|
|
266 |
while (count--) {
|
|
267 |
*dst++ = *src++;
|
|
268 |
}
|
|
269 |
# endif
|
|
270 |
#endif
|
|
271 |
} else {
|
|
272 |
while (count-- > 0) {
|
|
273 |
t = *src++;
|
|
274 |
*dst++ = t;
|
|
275 |
__STORE(self, t);
|
|
276 |
}
|
|
277 |
}
|
|
278 |
}
|
|
279 |
RETURN ( self );
|
|
280 |
}
|
|
281 |
}
|
|
282 |
}
|
|
283 |
}
|
|
284 |
}
|
|
285 |
%}
|
|
286 |
.
|
|
287 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
|
|
288 |
! !
|
|
289 |
|
|
290 |
!Array methodsFor:'testing'!
|
|
291 |
|
|
292 |
includes:anObject
|
|
293 |
"return true, if the argument, anObject is contained in the array
|
|
294 |
- reimplemented for speed"
|
|
295 |
|
|
296 |
|element|
|
|
297 |
|
|
298 |
%{ /* NOCONTEXT */
|
|
299 |
|
|
300 |
REGISTER int index;
|
|
301 |
REGISTER OBJ o;
|
|
302 |
int nIndex;
|
|
303 |
|
|
304 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
305 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
306 |
|
|
307 |
/* quick check using == */
|
|
308 |
o = anObject;
|
|
309 |
while (index < nIndex) {
|
|
310 |
if (_InstPtr(self)->i_instvars[index++] == o) {
|
|
311 |
RETURN ( true );
|
|
312 |
}
|
|
313 |
}
|
|
314 |
if (o == nil) {
|
|
315 |
RETURN ( false );
|
|
316 |
}
|
|
317 |
%}
|
|
318 |
.
|
|
319 |
%{
|
|
320 |
REGISTER int index;
|
|
321 |
int nIndex;
|
|
322 |
extern OBJ __eq;
|
|
323 |
static struct inlineCache eq = _ILC1;
|
|
324 |
|
|
325 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
326 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
327 |
|
|
328 |
/* slow check using = */
|
|
329 |
|
|
330 |
while (index < nIndex) {
|
|
331 |
element = _InstPtr(self)->i_instvars[index++];
|
|
332 |
if (element != nil) {
|
|
333 |
#ifdef PASS_ARG_REF
|
|
334 |
if ((*eq.ilc_func)(anObject,__eq, CON_COMMA nil,&eq,&element)==true)
|
|
335 |
#else
|
|
336 |
if ((*eq.ilc_func)(anObject,__eq, CON_COMMA nil,&eq,element)==true)
|
|
337 |
#endif
|
|
338 |
{
|
|
339 |
RETURN ( true );
|
|
340 |
}
|
|
341 |
}
|
|
342 |
}
|
|
343 |
%}
|
|
344 |
.
|
|
345 |
^ false
|
|
346 |
!
|
|
347 |
|
|
348 |
indexOf:anElement startingAt:start
|
|
349 |
"search the array for anElement; return index if found, 0 otherwise
|
|
350 |
- reimplemented for speed"
|
|
351 |
|
|
352 |
|element|
|
|
353 |
%{
|
|
354 |
REGISTER int index;
|
|
355 |
int nIndex, nInsts;
|
|
356 |
extern OBJ __eq;
|
|
357 |
static struct inlineCache eq = _ILC1;
|
|
358 |
|
|
359 |
if (_isSmallInteger(start)) {
|
|
360 |
index = _intVal(start) - 1;
|
|
361 |
if (index >= 0) {
|
|
362 |
nInsts = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
363 |
index += nInsts;
|
|
364 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
365 |
if (anElement != nil) {
|
|
366 |
while (index < nIndex) {
|
|
367 |
element = _InstPtr(self)->i_instvars[index++];
|
|
368 |
if (element != nil) {
|
|
369 |
if ((element == anElement)
|
|
370 |
#ifdef PASS_ARG_REF
|
|
371 |
|| ((*eq.ilc_func)(anElement,__eq, CON_COMMA nil,&eq,&element)
|
|
372 |
#else
|
|
373 |
|| ((*eq.ilc_func)(anElement,__eq, CON_COMMA nil,&eq,element)
|
|
374 |
#endif
|
|
375 |
== true)) {
|
|
376 |
RETURN ( _MKSMALLINT(index - nInsts) );
|
|
377 |
}
|
|
378 |
}
|
|
379 |
}
|
|
380 |
} else {
|
|
381 |
/* search for nil */
|
|
382 |
while (index < nIndex) {
|
|
383 |
if (_InstPtr(self)->i_instvars[index++] == nil) {
|
|
384 |
RETURN ( _MKSMALLINT(index - nInsts) );
|
|
385 |
}
|
|
386 |
}
|
|
387 |
}
|
|
388 |
}
|
|
389 |
}
|
|
390 |
%}
|
|
391 |
.
|
|
392 |
^ 0
|
|
393 |
!
|
|
394 |
|
|
395 |
identityIndexOf:anElement startingAt:start
|
|
396 |
"search the array for anElement; return index if found, 0 otherwise
|
|
397 |
- reimplemented for speed"
|
|
398 |
|
|
399 |
%{ /* NOCONTEXT */
|
|
400 |
|
|
401 |
REGISTER int index;
|
|
402 |
REGISTER OBJ el;
|
|
403 |
REGISTER OBJ *op;
|
|
404 |
REGISTER int nIndex;
|
|
405 |
int nInsts;
|
|
406 |
|
|
407 |
if (_isSmallInteger(start)) {
|
|
408 |
index = _intVal(start) - 1;
|
|
409 |
if (index >= 0) {
|
|
410 |
nInsts = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
411 |
index += nInsts;
|
|
412 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
413 |
el = anElement;
|
|
414 |
op = & (_InstPtr(self)->i_instvars[index]);
|
|
415 |
while (index++ < nIndex) {
|
|
416 |
if (*op++ == el) {
|
|
417 |
RETURN ( _MKSMALLINT(index - nInsts) );
|
|
418 |
}
|
|
419 |
}
|
|
420 |
RETURN ( _MKSMALLINT(0) );
|
|
421 |
}
|
|
422 |
}
|
|
423 |
%}
|
|
424 |
.
|
|
425 |
^ super identityIndexOf:anElement startingAt:start
|
|
426 |
! !
|
|
427 |
|
|
428 |
!Array methodsFor:'enumeration'!
|
|
429 |
|
|
430 |
do:aBlock
|
|
431 |
"evaluate the argument, aBlock for each element in the collection.
|
|
432 |
- reimplemented for speed"
|
|
433 |
|
|
434 |
|home element|
|
|
435 |
%{
|
|
436 |
REGISTER OBJFUNC codeVal;
|
|
437 |
REGISTER int index;
|
|
438 |
int nIndex;
|
|
439 |
extern OBJ _value_, Block;
|
|
440 |
static struct inlineCache val = _ILC1;
|
|
441 |
|
|
442 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
443 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
444 |
if (_isBlock(aBlock)
|
|
445 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
446 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
447 |
home = _BlockInstPtr(aBlock)->b_home;
|
|
448 |
for (; index < nIndex; index++) {
|
|
449 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
450 |
|
|
451 |
element = _InstPtr(self)->i_instvars[index];
|
|
452 |
#ifdef PASS_ARG_REF
|
|
453 |
(*codeVal)(home, CON_COMMA &element);
|
|
454 |
#else
|
|
455 |
(*codeVal)(home, CON_COMMA element);
|
|
456 |
#endif
|
|
457 |
}
|
|
458 |
} else {
|
|
459 |
for (; index < nIndex; index++) {
|
|
460 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
461 |
|
|
462 |
element = _InstPtr(self)->i_instvars[index];
|
|
463 |
#ifdef PASS_ARG_REF
|
|
464 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val, &element);
|
|
465 |
#else
|
|
466 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val, element);
|
|
467 |
#endif
|
|
468 |
}
|
|
469 |
}
|
|
470 |
%}
|
|
471 |
.
|
|
472 |
^ self
|
|
473 |
!
|
|
474 |
|
|
475 |
reverseDo:aBlock
|
|
476 |
"evaluate the argument, aBlock for each element in the collection in reverse order.
|
|
477 |
- reimplemented for speed"
|
|
478 |
|
|
479 |
|home element|
|
|
480 |
%{
|
|
481 |
REGISTER OBJFUNC codeVal;
|
|
482 |
REGISTER int index;
|
|
483 |
int nIndex, endIndex;
|
|
484 |
extern OBJ _value_, Block;
|
|
485 |
static struct inlineCache val = _ILC1;
|
|
486 |
|
|
487 |
endIndex = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
488 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
489 |
if (_isBlock(aBlock)
|
|
490 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
491 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
492 |
home = _BlockInstPtr(aBlock)->b_home;
|
|
493 |
for (index=nIndex-1; index >= endIndex; index--) {
|
|
494 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
495 |
|
|
496 |
element = _InstPtr(self)->i_instvars[index];
|
|
497 |
#ifdef PASS_ARG_REF
|
|
498 |
(*codeVal)(home, CON_COMMA &element);
|
|
499 |
#else
|
|
500 |
(*codeVal)(home, CON_COMMA element);
|
|
501 |
#endif
|
|
502 |
}
|
|
503 |
} else {
|
|
504 |
for (index=nIndex=1; index >= endIndex; index--) {
|
|
505 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
506 |
|
|
507 |
element = _InstPtr(self)->i_instvars[index];
|
|
508 |
#ifdef PASS_ARG_REF
|
|
509 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val, &element);
|
|
510 |
#else
|
|
511 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val, element);
|
|
512 |
#endif
|
|
513 |
}
|
|
514 |
}
|
|
515 |
%}
|
|
516 |
.
|
|
517 |
^ self
|
|
518 |
!
|
|
519 |
|
|
520 |
from:start to:stop do:aBlock
|
|
521 |
"evaluate the argument, aBlock for the elements starting at index start
|
|
522 |
up to (and including) stop in the collection.
|
|
523 |
- reimplemented for speed"
|
|
524 |
|
|
525 |
|home element|
|
|
526 |
%{
|
|
527 |
REGISTER OBJFUNC codeVal;
|
|
528 |
REGISTER int index;
|
|
529 |
int nIndex, nInsts;
|
|
530 |
extern OBJ _value_, Block;
|
|
531 |
static struct inlineCache val = _ILC1;
|
|
532 |
int indexLow, indexHigh;
|
|
533 |
|
|
534 |
if (_isSmallInteger(start) && _isSmallInteger(stop)) {
|
|
535 |
indexLow = _intVal(start);
|
|
536 |
if (indexLow > 0) {
|
|
537 |
indexHigh = _intVal(stop);
|
|
538 |
nInsts = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
539 |
indexLow += nInsts;
|
|
540 |
indexHigh += nInsts;
|
|
541 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
542 |
if (indexHigh <= nIndex) {
|
|
543 |
indexLow--;
|
|
544 |
indexHigh--;
|
|
545 |
if (_isBlock(aBlock)
|
|
546 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
547 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
548 |
home = _BlockInstPtr(aBlock)->b_home;
|
|
549 |
for (index=indexLow; index <= indexHigh; index++) {
|
|
550 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
551 |
|
|
552 |
#ifdef PASS_ARG_REF
|
|
553 |
element = _InstPtr(self)->i_instvars[index];
|
|
554 |
(*codeVal)(home, CON_COMMA &element);
|
|
555 |
#else
|
|
556 |
(*codeVal)(home, CON_COMMA _InstPtr(self)->i_instvars[index]);
|
|
557 |
#endif
|
|
558 |
}
|
|
559 |
} else {
|
|
560 |
for (index=indexLow; index <= indexHigh; index++) {
|
|
561 |
if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
|
|
562 |
|
|
563 |
element = _InstPtr(self)->i_instvars[index];
|
|
564 |
#ifdef PASS_ARG_REF
|
|
565 |
(*val.ilc_func)
|
|
566 |
(aBlock, _value_, CON_COMMA nil, &val, &element);
|
|
567 |
#else
|
|
568 |
(*val.ilc_func)
|
|
569 |
(aBlock, _value_, CON_COMMA nil, &val, element);
|
|
570 |
#endif
|
|
571 |
}
|
|
572 |
}
|
|
573 |
RETURN ( self );
|
|
574 |
}
|
|
575 |
}
|
|
576 |
}
|
|
577 |
%}
|
|
578 |
.
|
|
579 |
^ super from:start to:stop do:aBlock
|
|
580 |
!
|
|
581 |
|
|
582 |
nonNilElementsDo:aBlock
|
|
583 |
"evaluate the argument, aBlock for each non-nil element"
|
|
584 |
|
|
585 |
|home element|
|
|
586 |
%{
|
|
587 |
REGISTER OBJFUNC codeVal;
|
|
588 |
REGISTER int index;
|
|
589 |
int nIndex;
|
|
590 |
extern OBJ _value_, Block;
|
|
591 |
static struct inlineCache val = _ILC1;
|
|
592 |
|
|
593 |
index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
|
|
594 |
nIndex = (_qSize(self) - OHDR_SIZE) / sizeof(OBJ);
|
|
595 |
if (_isBlock(aBlock)
|
|
596 |
&& ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
|
|
597 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) {
|
|
598 |
home = _BlockInstPtr(aBlock)->b_home;
|
|
599 |
for (; index < nIndex; index++) {
|
|
600 |
if (InterruptPending != nil) interrupt(CONARG);
|
|
601 |
|
|
602 |
element = _InstPtr(self)->i_instvars[index];
|
|
603 |
if (element != nil)
|
|
604 |
#ifdef PASS_ARG_REF
|
|
605 |
(*codeVal)(home, CON_COMMA &element);
|
|
606 |
#else
|
|
607 |
(*codeVal)(home, CON_COMMA element);
|
|
608 |
#endif
|
|
609 |
}
|
|
610 |
} else {
|
|
611 |
for (; index < nIndex; index++) {
|
|
612 |
if (InterruptPending != nil) interrupt(CONARG);
|
|
613 |
|
|
614 |
element = _InstPtr(self)->i_instvars[index];
|
|
615 |
if (element != nil)
|
|
616 |
#ifdef PASS_ARG_REF
|
|
617 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val, &element);
|
|
618 |
#else
|
|
619 |
(*val.ilc_func)(aBlock, _value_, CON_COMMA nil, &val, element);
|
|
620 |
#endif
|
|
621 |
}
|
|
622 |
}
|
|
623 |
%}
|
|
624 |
.
|
|
625 |
^ self
|
|
626 |
! !
|