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