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