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