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