ByteArray.st
author Claus Gittinger <cg@exept.de>
Mon, 27 May 2019 16:53:37 +0200
changeset 24192 18512bf68422
parent 23925 fcde2f1eefbe
child 24246 5891fd2af1ec
permissions -rw-r--r--
#DOCUMENTATION by cg class: Integer category of: #anyBitOfMagnitudeFrom:to: #highBitOfMagnitude
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23925
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
     1
"{ Encoding: utf8 }"
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
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: 148
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
"
5425
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
    14
"{ Package: 'stx:libbasic' }"
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
    15
17377
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
    16
"{ NameSpace: Smalltalk }"
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
    17
3208
2d71538b9fd5 now subclass of UIBytes - which contains common protocol
Claus Gittinger <cg@exept.de>
parents: 3205
diff changeset
    18
UninterpretedBytes variableByteSubclass:#ByteArray
1002
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    19
	instanceVariableNames:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    20
	classVariableNames:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    21
	poolDictionaries:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    22
	category:'Collections-Arrayed'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
    25
!ByteArray class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    27
copyright
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    28
"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    29
 COPYRIGHT (c) 1989 by Claus Gittinger
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    30
	      All Rights Reserved
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    31
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    32
 This software is furnished under a license and may be used
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    33
 only in accordance with the terms of that license and with the
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    35
 be provided or otherwise made available to, or used by, any
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    36
 other person.  No title to or ownership of the software is
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    37
 hereby transferred.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    38
"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    39
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    40
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    42
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    43
    ByteArrays store integers in the range 0..255.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    44
    In contrast to normal arrays (which store pointers to their elements),
20629
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    45
    byteArrays store the values in a dense & compact way. 
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    46
    ByteArrays can be used to hold the data for bitmaps, images and other bulk data.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    47
    ByteArrays are also used to store the bytecode-instructions of an
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    48
    interpreted method and are used as superclass for Strings.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    49
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    50
    ByteArrays can be used as literals i.e. you can enter ByteArray-constants
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    51
    as #[ element1 element2 .... elementN] and also use byteArray constants
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    52
    as elements in a constant array.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    53
    As in: #( #[1 1 1] #[2 2 2] #[3 3 3])
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    54
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    55
    If you have to communicate structure-data (in the C-sense) with external
20629
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    56
    programs/data-bases, see a companion class (Structure).
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    57
    It allows the definition of subclasses of ByteArray, which transparently fetch
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    58
    and store C-structure fields.
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
    59
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
    60
    [memory requirements:]
20629
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    61
        OBJ-HEADER + size
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
    62
2145
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1974
diff changeset
    63
    [warning:]
20629
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    64
        read the warning about 'growing fixed size collection'
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    65
        in ArrayedCollection's documentation
2145
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1974
diff changeset
    66
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
    67
    [author:]
20629
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    68
        Claus Gittinger
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
    69
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
    70
    [See also:]
20629
0fc29277f896 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20519
diff changeset
    71
        Array CharacterArray String
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    72
"
2
claus
parents: 1
diff changeset
    73
! !
claus
parents: 1
diff changeset
    74
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
    75
!ByteArray class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
uninitializedNew:anInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
    "return a new instance of the receiver with uninitialized
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
     (i.e. undefined) contents. The indexed elements have any random
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    80
     value. However, any named instance variables are still nilled.
75
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    81
     For use, when contents will be set anyway shortly after - this
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    82
     is a bit faster than the regular basicNew:, which clears the bytes.
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    83
     Of course, it only makes a difference for very big ByteArrays, such
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    84
     as used for images/bitmaps.
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    85
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    86
     Notice: if you want to port code using uninitializedNew: to another
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    87
     smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling
75
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    88
     method to the ByteArray class of the other smalltalk."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
    OBJ newobj;
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
    INT instsize, nInstVars, nindexedinstvars;
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
    REGISTER OBJ *op;
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
249
claus
parents: 221
diff changeset
    95
    if (__isSmallInteger(anInteger)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    96
	nindexedinstvars = __intVal(anInteger);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    97
	if (nindexedinstvars >= 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    98
	    if (self == ByteArray) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    99
		/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   100
		 * the most common case
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   101
		 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   102
		instsize = OHDR_SIZE + nindexedinstvars;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   103
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   104
		    __qCheckedNew(newobj, instsize);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   105
		    __InstPtr(newobj)->o_class = self;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   106
		    __qSTORE(newobj, self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   107
		    RETURN (newobj );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   108
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   109
	    } else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   110
		/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   111
		 * Take care for subclasses like TwoByteString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   112
		 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   113
		switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   114
		case BYTEARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   115
		    break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   116
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   117
		case WORDARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   118
		case SWORDARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   119
		    nindexedinstvars *= 2;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   120
		    break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   121
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   122
		case LONGARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   123
		case SLONGARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   124
		    nindexedinstvars *= 4;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   125
		    break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   126
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   127
		default:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   128
		    /* don't know about this array type, delegate to super */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   129
		    goto out;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   130
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   131
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   132
	    nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   133
	    instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   134
	    __PROTECT_CONTEXT__
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   135
	    __qNew(newobj, instsize);   /* OBJECT ALLOCATION */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   136
	    __UNPROTECT_CONTEXT__
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   137
	    if (newobj != nil) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   138
		__InstPtr(newobj)->o_class = self;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   139
		__qSTORE(newobj, self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   140
		if (nInstVars) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   141
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   142
		     * still have to nil out named instvars ...
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   143
		     */
788
e80f1c42b87b dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
   144
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   145
		    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
#else
249
claus
parents: 221
diff changeset
   147
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   148
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   149
		     * knowing that nil is 0
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   150
		     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   151
		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
249
claus
parents: 221
diff changeset
   152
# else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   153
		    op = __InstPtr(newobj)->i_instvars;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   154
		    while (nInstVars--)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   155
			*op++ = nil;
249
claus
parents: 221
diff changeset
   156
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   157
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   158
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   159
		RETURN ( newobj );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   160
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   161
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
    }
8159
ac6725a62e17 #uninitializedNew: - take care of WORDARRAYS etc.
Stefan Vogel <sv@exept.de>
parents: 8096
diff changeset
   163
out:;
5425
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
   164
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
    ^ self basicNew:anInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
11502
64d1cb6c2062 changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 11265
diff changeset
   168
22032
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
   169
23710
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
   170
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
   171
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   172
!ByteArray class methodsFor:'queries'!
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   173
13706
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   174
elementByteSize
16851
e7212682103b comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16807
diff changeset
   175
    "for bit-like containers, return the number of bytes stored per element.
e7212682103b comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16807
diff changeset
   176
     Here, 1 is returned"
e7212682103b comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16807
diff changeset
   177
13706
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   178
    ^ 1
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   179
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   180
    "Created: / 15-09-2011 / 14:12:53 / cg"
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   181
!
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   182
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   183
isBuiltInClass
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   184
    "return true if this class is known by the run-time-system.
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   185
     Here, true is returned for myself, false for subclasses."
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   186
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   187
    ^ self == ByteArray
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   188
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   189
    "Modified: 23.4.1996 / 15:56:25 / cg"
19934
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   190
!
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   191
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   192
maxVal
19942
141bc26e9fc1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19936
diff changeset
   193
    "the minimum value which can be stored in instances of me.
141bc26e9fc1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19936
diff changeset
   194
     For ByteArrays, this is 255"
19934
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   195
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   196
    ^ 255
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   197
!
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   198
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   199
minVal
19942
141bc26e9fc1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19936
diff changeset
   200
    "the minimum value which can be stored in instances of me.
141bc26e9fc1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19936
diff changeset
   201
     For ByteArrays, this is 0"
19934
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   202
392ce4c308c6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19764
diff changeset
   203
    ^ 0
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   204
! !
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   205
22032
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
   206
23710
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
   207
10884
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   208
!ByteArray methodsFor:'Compatibility-Squeak'!
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   209
12144
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   210
bitXor:aByteArray
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   211
    "return a new byteArray containing the bitWise-xor of the receiver's and the
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   212
     argument's bytes"
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   213
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   214
    |size size1|
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   215
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   216
    "size := self size min:aByteArray size"
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   217
    size := self size.
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   218
    size1 := aByteArray size.
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   219
    size1 < size ifTrue:[
19936
335d0ad2a9a8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19934
diff changeset
   220
        size := size1.
12144
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   221
    ].
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   222
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   223
    ^ self copy
19936
335d0ad2a9a8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19934
diff changeset
   224
        bitXorBytesFrom:1 to:size with:aByteArray startingAt:1;
335d0ad2a9a8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19934
diff changeset
   225
        yourself.
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   226
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   227
    "
19936
335d0ad2a9a8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19934
diff changeset
   228
     #[0 1 2 3 4] bitXor:#[0 1 2 3 4]
335d0ad2a9a8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19934
diff changeset
   229
     #[0 1 2 3 4] bitXor:#[0 1 2 3]
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   230
    "
10884
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   231
! !
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   232
21426
7ef931a354d0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20629
diff changeset
   233
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   234
!ByteArray methodsFor:'accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   236
basicAt:index
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   237
    "return the indexed instance variable with index, anInteger
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   238
     - redefined here to be slighly faster than the default in Object.
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   239
     Q: is it worth the extra code ?"
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   240
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   241
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   242
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   243
    REGISTER int indx;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   244
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   245
    REGISTER OBJ cls;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   246
    REGISTER int nIndex;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   247
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   248
    if (__isSmallInteger(index)) {
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   249
	indx = __intVal(index) - 1;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   250
	slf = self;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   251
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   252
	    if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   253
		!= __MASKSMALLINT(BYTEARRAY)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   254
		goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   255
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   256
	    if (indx < 0) goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   257
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   258
	}
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   259
	nIndex = __byteArraySize(slf);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   260
	if ((unsigned)indx < (unsigned)nIndex) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   261
	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   262
	}
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   263
    }
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   264
  fail: ;
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   265
%}.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   266
    ^ super basicAt:index
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   267
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   268
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   269
basicAt:index put:value
1230
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   270
    "set the indexed instance variable with index, anInteger to value.
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   271
     Returns value (sigh).
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   272
     - redefined here to be slighly faster than the default in Object.
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   273
     Q: is it worth the extra code ?"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
    REGISTER int indx;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
    int nIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   279
    int val;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   280
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   281
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
249
claus
parents: 221
diff changeset
   283
    if (__bothSmallInteger(index, value)) {
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   284
	val = __intVal(value);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   285
	if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   286
	    indx = __intVal(index) - 1;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   287
	    slf = self;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   288
	    if ((cls = __qClass(slf)) != @global(ByteArray)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   289
		if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   290
		    != __MASKSMALLINT(BYTEARRAY)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   291
		    goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   292
		}
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   293
		if (indx < 0) goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   294
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   295
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   296
	    nIndex = __byteArraySize(slf);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   297
	    if ((unsigned)indx < (unsigned)nIndex) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   298
		__ByteArrayInstPtr(slf)->ba_element[indx] = val;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   299
		RETURN ( value );
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   300
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   301
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   302
    }
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   303
  fail: ;
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   304
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
    ^ super basicAt:index put:value
1230
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   306
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   307
    "Modified: 19.4.1996 / 11:14:40 / cg"
2
claus
parents: 1
diff changeset
   308
!
claus
parents: 1
diff changeset
   309
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   310
bitAt:index
11502
64d1cb6c2062 changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 11265
diff changeset
   311
    "return the bit at index (1 based index) as 0 or 1"
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   312
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   313
    |byteIndex bitIndex0 byte|
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   314
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   315
%{  /* NOCONTEXT */
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   316
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   317
    REGISTER int indx;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   318
    REGISTER int byte;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   319
    int nIndex;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   320
    REGISTER OBJ slf;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   321
    REGISTER OBJ cls;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   322
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   323
    if (__isSmallInteger(index)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   324
	indx = __intVal(index) - 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   325
	slf = self;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   326
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   327
	byte = indx / 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   328
	indx = indx % 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   329
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   330
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   331
	    if (indx < 0) goto badIndex;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   332
	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   333
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   334
	nIndex = __byteArraySize(slf);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   335
	if ((unsigned)byte < (unsigned)nIndex) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   336
	    RETURN ( __mkSmallInteger(((__ByteArrayInstPtr(slf)->ba_element[byte] & (1 << indx)) != 0)) );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   337
	}
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   338
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   339
badIndex: ;
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   340
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   341
    byteIndex := ((index-1) // 8) + 1.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   342
    bitIndex0 := ((index-1) \\ 8).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   343
    byte := self at:byteIndex.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   344
    ^  byte bitTest:(1 bitShift:bitIndex0).
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   345
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   346
   "
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   347
     #[ 1 1 1 1 ] bitAt:9
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   348
     #[ 1 1 1 1 ] bitAt:11
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   349
     #[ 2 2 2 2 ] bitAt:10
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   350
   "
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   351
!
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   352
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   353
bitClearAt:index
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   354
    "clear the bit at index (index starts with 1)"
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   355
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   356
    |byteIndex bitIndex0 byte|
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   357
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   358
%{  /* NOCONTEXT */
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   359
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   360
    REGISTER int indx;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   361
    REGISTER int byte;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   362
    int nIndex;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   363
    REGISTER OBJ slf;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   364
    REGISTER OBJ cls;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   365
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   366
    if (0 /* __isSmallInteger(index) */) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   367
	indx = __intVal(index) - 1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   368
	slf = self;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   369
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   370
	byte = indx / 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   371
	indx = indx % 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   372
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   373
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   374
	    if (indx < 0) goto badIndex;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   375
	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   376
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   377
	nIndex = __byteArraySize(slf);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   378
	if ((unsigned)byte < (unsigned)nIndex) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   379
	    __ByteArrayInstPtr(slf)->ba_element[byte] &= ~(1 << indx);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   380
	    RETURN (slf);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   381
	}
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   382
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   383
badIndex: ;
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   384
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   385
    byteIndex := ((index-1) // 8) + 1.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   386
    bitIndex0 := ((index-1) \\ 8).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   387
    byte := self at:byteIndex.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   388
    byte := byte bitClear:(1 bitShift:bitIndex0).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   389
    self at:byteIndex put:byte.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   390
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   391
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   392
     #[0 0 0 0] copy bitClearAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   393
     #[0 0 0 0] copy bitClearAt:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   394
     #[0 0 0 0] copy bitClearAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   395
     #[0 0 0 0] copy bitClearAt:9
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   396
    "
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   397
   "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   398
     #[ 0 0 0 0 ] bitSetAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   399
     #[ 0 0 0 0 ] bitSetAt:4
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   400
     #[ 0 0 0 0 ] bitSetAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   401
     #[ 0 0 0 0 ] bitSetAt:9
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   402
     #[ 0 0 0 0 ] bitSetAt:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   403
     #[ 0 0 0 0 ] bitSetAt:11
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   404
   "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   405
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   406
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   407
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   408
!
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   409
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   410
bitSetAt:index
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   411
    "set the bit at index (index starts with 1)"
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   412
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   413
    |byteIndex bitIndex0 byte|
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   414
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   415
%{  /* NOCONTEXT */
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   416
19134
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   417
    if (__isSmallInteger(index)
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   418
     && (__qClass(self) == @global(ByteArray))) {
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   419
        int indx;
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   420
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   421
        indx = __intVal(index) - 1;
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   422
        if (indx >= 0) {
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   423
            int byteIndex;
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   424
            int bitIndex;
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   425
            int nIndex;
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   426
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   427
            byteIndex = indx / 8;
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   428
            bitIndex = indx % 8;
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   429
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   430
            nIndex = __byteArraySize(self);
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   431
            if ((unsigned)byteIndex < (unsigned)nIndex) {
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   432
                __ByteArrayInstPtr(self)->ba_element[byteIndex] |= (1 << bitIndex);
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   433
                RETURN (self);
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   434
            }
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   435
        }
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   436
    }
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   437
%}.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   438
    byteIndex := ((index-1) // 8) + 1.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   439
    bitIndex0 := ((index-1) \\ 8).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   440
    byte := self at:byteIndex.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   441
    byte := byte bitOr:(1 bitShift:bitIndex0).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   442
    self at:byteIndex put:byte.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   443
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   444
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   445
     #[0 0 0 0] copy bitSetAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   446
     #[0 0 0 0] copy bitSetAt:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   447
     #[0 0 0 0] copy bitSetAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   448
     #[0 0 0 0] copy bitSetAt:9
19134
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   449
     #[0 0 0 0] copy bitSetAt:32
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   450
     #[0 0 0 0] copy bitSetAt:33
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   451
     #[0 0 0 0] copy bitSetAt:0
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   452
    "
19134
eaa91cb0ef1b #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19048
diff changeset
   453
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   454
     #[ 0 0 0 0 ] bitSetAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   455
     #[ 0 0 0 0 ] bitSetAt:4
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   456
     #[ 0 0 0 0 ] bitSetAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   457
     #[ 0 0 0 0 ] bitSetAt:9
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   458
     #[ 0 0 0 0 ] bitSetAt:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   459
     #[ 0 0 0 0 ] bitSetAt:11
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   460
   "
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   461
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   462
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   463
!ByteArray methodsFor:'accessing-bytes'!
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   464
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   465
byteAt:index
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   466
    "return the byte at index.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   467
     For ByteArray, this is the same as basicAt:;
249
claus
parents: 221
diff changeset
   468
     however, for strings or symbols, this returns a numeric byteValue
claus
parents: 221
diff changeset
   469
     instead of a character."
claus
parents: 221
diff changeset
   470
claus
parents: 221
diff changeset
   471
%{  /* NOCONTEXT */
claus
parents: 221
diff changeset
   472
claus
parents: 221
diff changeset
   473
    REGISTER int indx;
claus
parents: 221
diff changeset
   474
    int nIndex;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   475
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   476
    REGISTER OBJ cls;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   477
249
claus
parents: 221
diff changeset
   478
    if (__isSmallInteger(index)) {
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   479
	indx = __intVal(index) - 1;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   480
	slf = self;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   481
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   482
	    if (indx < 0) goto badIndex;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   483
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   484
	}
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   485
	nIndex = __byteArraySize(slf);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   486
	if ((unsigned)indx < (unsigned)nIndex) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   487
	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   488
	}
249
claus
parents: 221
diff changeset
   489
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   490
badIndex: ;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   491
%}.
249
claus
parents: 221
diff changeset
   492
    ^ (super basicAt:index) asInteger
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   493
!
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   494
249
claus
parents: 221
diff changeset
   495
byteAt:index put:value
claus
parents: 221
diff changeset
   496
    "set the byte at index. For ByteArray, this is the same as basicAt:put:.
claus
parents: 221
diff changeset
   497
     However, for Strings, this expects a byteValue to be stored."
claus
parents: 221
diff changeset
   498
claus
parents: 221
diff changeset
   499
%{  /* NOCONTEXT */
claus
parents: 221
diff changeset
   500
claus
parents: 221
diff changeset
   501
    REGISTER int indx;
claus
parents: 221
diff changeset
   502
    int nIndex;
claus
parents: 221
diff changeset
   503
    int val;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   504
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   505
    REGISTER OBJ cls;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   506
249
claus
parents: 221
diff changeset
   507
    if (__bothSmallInteger(index, value)) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   508
        val = __intVal(value);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   509
        if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   510
            indx = __intVal(index) - 1;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   511
            slf = self;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   512
            if ((cls = __qClass(slf)) != ByteArray) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   513
                if (indx < 0) goto badIndex;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   514
                if (cls == ImmutableByteArray) goto badIndex; 
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   515
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   516
            }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   517
            nIndex = __byteArraySize(slf);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   518
            if ((unsigned)indx < (unsigned)nIndex) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   519
                __ByteArrayInstPtr(slf)->ba_element[indx] = val;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   520
                RETURN ( value );
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   521
            }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   522
        }
249
claus
parents: 221
diff changeset
   523
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   524
badIndex: ;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   525
%}.
249
claus
parents: 221
diff changeset
   526
    ^ super basicAt:index put:value
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   527
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   528
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   529
!ByteArray methodsFor:'accessing-longs'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   530
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   531
unsignedInt32At:index put:value
2
claus
parents: 1
diff changeset
   532
    "set the 4-bytes starting at index from the (unsigned) Integer value.
359
claus
parents: 343
diff changeset
   533
     The value should be in the range 0 to 16rFFFFFFFF
claus
parents: 343
diff changeset
   534
     (for negative values, the stored value is not defined).
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   535
     The value is stored in the machine's natural byte order.
359
claus
parents: 343
diff changeset
   536
     Q: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
claus
parents: 343
diff changeset
   537
claus
parents: 343
diff changeset
   538
    |t|
claus
parents: 343
diff changeset
   539
claus
parents: 343
diff changeset
   540
%{  /* NOCONTEXT */
claus
parents: 343
diff changeset
   541
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   542
    REGISTER INT indx;
359
claus
parents: 343
diff changeset
   543
    int nIndex;
claus
parents: 343
diff changeset
   544
    union {
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   545
        unsigned char u_char[4];
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   546
        unsigned int u_uint;
359
claus
parents: 343
diff changeset
   547
    } val;
claus
parents: 343
diff changeset
   548
    OBJ cls;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   549
    unsigned char *byteP;
359
claus
parents: 343
diff changeset
   550
claus
parents: 343
diff changeset
   551
    if (__isSmallInteger(index)) {
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   552
        if (__isSmallInteger(value)) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   553
            val.u_uint = __intVal(value);
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   554
        } else {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   555
            val.u_uint = __longIntVal(value);
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   556
            if (val.u_uint == 0) goto error;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   557
        }
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   558
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   559
        indx = __intVal(index);
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   560
        if (indx > 0) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   561
            if ((cls = __qClass(self)) != @global(ByteArray)) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   562
                if (cls == ImmutableByteArray) goto error;
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   563
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   564
            }
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   565
            nIndex = __qSize(self) - OHDR_SIZE;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   566
            if ((indx+3) <= nIndex) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   567
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   568
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   569
                ((unsigned int *)byteP)[0] = val.u_uint;
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   570
#else
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   571
                if (((unsigned INT)byteP & 3) == 0) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   572
                    ((unsigned int *)byteP)[0] = val.u_uint;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   573
                } else {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   574
                    byteP[0] = val.u_char[0];
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   575
                    byteP[1] = val.u_char[1];
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   576
                    byteP[2] = val.u_char[2];
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   577
                    byteP[3] = val.u_char[3];
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   578
                }
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   579
#endif
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   580
                RETURN ( value );
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   581
            }
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   582
        }
359
claus
parents: 343
diff changeset
   583
    }
claus
parents: 343
diff changeset
   584
  error: ;
claus
parents: 343
diff changeset
   585
%}.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   586
    ^ super unsignedInt32At:index put:value.
359
claus
parents: 343
diff changeset
   587
claus
parents: 343
diff changeset
   588
    "
claus
parents: 343
diff changeset
   589
     |b|
claus
parents: 343
diff changeset
   590
     b := ByteArray new:4.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   591
     b unsignedInt32At:1 put:16r04030201.
359
claus
parents: 343
diff changeset
   592
     b inspect
claus
parents: 343
diff changeset
   593
    "
claus
parents: 343
diff changeset
   594
!
claus
parents: 343
diff changeset
   595
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   596
unsignedInt32At:index put:value MSB:msb
359
claus
parents: 343
diff changeset
   597
    "set the 4-bytes starting at index from the (unsigned) Integer value.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   598
     The value must be in the range 0 to 16rFFFFFFFF.
359
claus
parents: 343
diff changeset
   599
     The value is stored MSB-first if msb is true; LSB-first otherwise.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   600
     question: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
2
claus
parents: 1
diff changeset
   601
claus
parents: 1
diff changeset
   602
    |t|
claus
parents: 1
diff changeset
   603
claus
parents: 1
diff changeset
   604
%{  /* NOCONTEXT */
claus
parents: 1
diff changeset
   605
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   606
    REGISTER INT indx;
2
claus
parents: 1
diff changeset
   607
    int nIndex;
claus
parents: 1
diff changeset
   608
    int val;
249
claus
parents: 221
diff changeset
   609
    OBJ cls;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   610
    unsigned char *byteP;
2
claus
parents: 1
diff changeset
   611
359
claus
parents: 343
diff changeset
   612
    if (__isSmallInteger(index)) {
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   613
        if (__isSmallInteger(value)) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   614
            val = __intVal(value);
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   615
        } else {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   616
            val = __longIntVal(value);
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   617
            if (val == 0) goto error;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   618
        }
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   619
        indx = __intVal(index);
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   620
        if (indx > 0) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   621
            if ((cls = __qClass(self)) != @global(ByteArray)) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   622
                if (cls == ImmutableByteArray) goto error;
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   623
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   624
            }        
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   625
            nIndex = __qSize(self) - OHDR_SIZE;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   626
            if ((indx+3) <= nIndex) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   627
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   628
                if (msb == true) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   629
                    /*
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   630
                     * most significant byte first (i.e sparc order)
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   631
                     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   632
#if defined(__MSBFIRST__)
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   633
                    if (((INT)byteP & 3) == 0) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   634
                        ((int *)byteP)[0] = val;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   635
                    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   636
#endif
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   637
                    {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   638
                        byteP[3] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   639
                        val >>= 8;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   640
                        byteP[2] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   641
                        val >>= 8;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   642
                        byteP[1] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   643
                        val >>= 8;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   644
                        byteP[0] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   645
                    }
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   646
                } else {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   647
                    /*
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   648
                     * least significant byte first (i.e i386/alpha order)
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   649
                     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   650
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   651
                    ((int *)byteP)[0] = val;
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   652
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   653
# if defined(__LSBFIRST__)
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   654
                    if (((unsigned INT)byteP & 3) == 0) {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   655
                        ((int *)byteP)[0] = val;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   656
                    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   657
# endif
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   658
                    {
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   659
                        byteP[0] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   660
                        val >>= 8;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   661
                        byteP[1] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   662
                        val >>= 8;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   663
                        byteP[2] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   664
                        val >>= 8;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   665
                        byteP[3] = val & 0xFF;
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   666
                    }
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   667
#endif
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   668
                }
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   669
                RETURN ( value );
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   670
            }
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   671
        }
2
claus
parents: 1
diff changeset
   672
    }
359
claus
parents: 343
diff changeset
   673
  error: ;
claus
parents: 343
diff changeset
   674
%}.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   675
    ^ super unsignedInt32At:index put:value MSB:msb
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   676
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   677
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   678
     |b|
359
claus
parents: 343
diff changeset
   679
     b := ByteArray new:8.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   680
     b unsignedInt32At:1 put:16r04030201 MSB:true.
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   681
     b unsignedInt32At:5 put:16r04030201 MSB:false.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   682
     b inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   683
    "
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   684
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   685
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   686
!ByteArray methodsFor:'accessing-shorts'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   687
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   688
unsignedInt16At:index
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   689
    "return the 2-bytes starting at index as an (unsigned) Integer.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   690
     The value is retrieved in the machine's natural byte order
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   691
     Notice: 
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   692
        the index is a byte index; thus, this allows for unaligned access to
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   693
        words on any boundary.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   694
     Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   695
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   696
%{  /* NOCONTEXT */
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   697
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   698
    REGISTER INT indx;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   699
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   700
    union {
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   701
        unsigned char u_char[2];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   702
        unsigned short u_ushort;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   703
    } val;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   704
    unsigned char *byteP;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   705
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   706
    if (__isSmallInteger(index)) {
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   707
        indx = __intVal(index);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   708
        if (indx > 0) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   709
            if (!__isByteArrayLike(self))
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   710
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   711
            nIndex = __byteArraySize(self);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   712
            if ((indx+1) <= nIndex) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   713
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   714
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   715
                val.u_ushort = ((unsigned short *)byteP)[0];
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   716
#else
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   717
                val.u_char[0] = byteP[0];
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   718
                val.u_char[1] = byteP[1];
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   719
#endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   720
                RETURN ( __mkSmallInteger((val.u_ushort)) );
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   721
            }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   722
        }
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   723
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   724
%}.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   725
    ^ super unsignedInt16At:index
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   726
!
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   727
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   728
unsignedInt16At:index MSB:msb
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   729
    "return the 2-bytes starting at index as an (unsigned) Integer.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   730
     The value is retrieved MSB (high 8 bits at lower index) if msb is true;
21426
7ef931a354d0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20629
diff changeset
   731
     LSB-first (i.e. low 8-bits at lower byte index) if it's false.
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   732
     Notice: 
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   733
        the index is a byte index; thus, this allows for unaligned access to
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   734
        words on any boundary.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   735
     Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   736
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   737
%{  /* NOCONTEXT */
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   738
    REGISTER INT indx;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   739
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   740
    int val;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   741
    unsigned char *byteP;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   742
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   743
    if (__isSmallInteger(index)) {
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   744
        indx = __intVal(index);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   745
        if (indx > 0) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   746
            if (!__isByteArrayLike(self))
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   747
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   748
            nIndex = __byteArraySize(self);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   749
            if ((indx+1) <= nIndex) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   750
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   751
                if (msb == true) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   752
                    /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   753
                     * most significant byte first (i.e sparc order)
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   754
                     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   755
#if defined(__MSBFIRST__)
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   756
                    /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   757
                     * mhmh to be measured:
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   758
                     *   the if may hurt more than the additional
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   759
                     *   memory cycles on some machines ...
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   760
                     */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   761
                    if (((INT)byteP & 1) == 0) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   762
                        /* aligned */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   763
                        val = ((unsigned short *)byteP)[0];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   764
                    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   765
#endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   766
                    {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   767
                        val = byteP[0];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   768
                        val = (val << 8) + byteP[1];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   769
                    }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   770
                } else {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   771
                    /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   772
                     * least significant byte first (i.e i386/alpha order)
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   773
                     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   774
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   775
                    val = ((unsigned short *)byteP)[0];
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   776
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   777
# if defined(__LSBFIRST__)
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   778
                    /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   779
                     * mhmh to be measured:
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   780
                     *   the if may hurt more than the additional
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   781
                     *   memory cycles on some machines ...
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   782
                     */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   783
                    if (((INT)byteP & 1) == 0) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   784
                        /* aligned */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   785
                        val = ((unsigned short *)byteP)[0];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   786
                    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   787
# endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   788
                    {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   789
                        val = byteP[1];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   790
                        val = (val << 8) + byteP[0];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   791
                    }
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   792
#endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   793
                }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   794
                RETURN ( __mkSmallInteger(val) );
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   795
            }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   796
        }
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   797
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   798
%}.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   799
    ^ super unsignedInt16At:index MSB:msb
21426
7ef931a354d0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20629
diff changeset
   800
7ef931a354d0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20629
diff changeset
   801
    "Modified (comment): / 13-02-2017 / 19:56:53 / cg"
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   802
!
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   803
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   804
unsignedInt16At:index put:value
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   805
    "set the 2-bytes starting at index from the (unsigned) Integer value.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   806
     The stored value must be in the range 0 .. 16rFFFF.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   807
     The value is stored in the machine's natural byteorder,
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   808
     i.e. this method should only be used to fill byteArrays which are
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   809
     used internally (not passed to other machines).
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   810
     Notice: 
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   811
        the index is a byte index; thus, this allows for unaligned access to
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   812
        words on any boundary.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   813
     Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   814
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   815
%{  /* NOCONTEXT */
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   816
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   817
    REGISTER INT indx;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   818
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   819
    int v;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   820
    union {
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   821
        unsigned char u_char[2];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   822
        unsigned short u_ushort;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   823
    } val;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   824
    unsigned char *byteP;
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   825
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   826
    if (__bothSmallInteger(index, value)) {
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   827
        indx = __intVal(index);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   828
        if (indx > 0) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   829
            if (!__isByteArray(self)) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   830
                OBJ cls = __qClass(self);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   831
                if (cls == ImmutableByteArray) goto immutable;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   832
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   833
            }
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   834
            nIndex = __byteArraySize(self);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   835
            if ((indx+1) <= nIndex) {
19482
9067334aa4b7 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19414
diff changeset
   836
                v = __intVal(value);
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   837
                if ((v & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   838
                    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   839
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
19482
9067334aa4b7 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19414
diff changeset
   840
                    ((unsigned short *)byteP)[0] = v;
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   841
#else
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   842
                    /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   843
                     * mhmh to be measured:
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   844
                     *   the if may hurt more than the additional
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   845
                     *   memory cycles on some machines ...
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   846
                     */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   847
                    if (((INT)byteP & 1) == 0) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   848
                        /* aligned */
19482
9067334aa4b7 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19414
diff changeset
   849
                        ((unsigned short *)byteP)[0] = v;
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   850
                    } else {
19482
9067334aa4b7 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 19414
diff changeset
   851
                        val.u_ushort = v;
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   852
                        byteP[0] = val.u_char[0];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   853
                        byteP[1] = val.u_char[1];
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   854
                    }
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   855
#endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   856
                    RETURN ( value );
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   857
                }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   858
            }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   859
        }
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   860
    }
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   861
immutable: ;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   862
%}.
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   863
    ^ self unsignedInt16At:index put:value MSB:IsBigEndian
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   864
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   865
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   866
     |b|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   867
     b := ByteArray new:4.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   868
     b unsignedInt16At:1 put:16r0102.
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   869
     b unsignedInt16At:3 put:16r0304.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   870
     b inspect
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   871
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   872
!
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   873
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   874
unsignedInt16At:index put:value MSB:msb
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   875
    "set the 2-bytes starting at index from the (unsigned) Integer value.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   876
     The stored value must be in the range 0 .. 16rFFFF.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   877
     The value is stored LSB-first (i.e. the low 8bits are stored at the
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   878
     lower index) if msb is false, MSB-first otherwise.
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   879
     Notice: 
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   880
        the index is a byte index; thus, this allows for unaligned access to
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   881
        words on any boundary.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   882
     Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   883
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   884
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   885
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   886
    REGISTER INT indx;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   887
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   888
    int val;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   889
    OBJ cls;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   890
    unsigned char *byteP;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   891
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   892
    if (__bothSmallInteger(index, value)) {
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   893
        indx = __intVal(index);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   894
        if (indx > 0) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   895
            if (!__isByteArray(self)) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   896
                OBJ cls = __qClass(self);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   897
                if (cls == ImmutableByteArray) goto immutable;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   898
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   899
            }        
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   900
            nIndex = __byteArraySize(self);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   901
            if ((indx+1) <= nIndex) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   902
                val = __intVal(value);
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   903
                if ((val & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   904
                    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   905
                    if (msb == true) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   906
                        /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   907
                         * most significant byte first (i.e sparc order)
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   908
                         */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   909
#if defined(__MSBFIRST__)
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   910
                        /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   911
                         * mhmh to be measured:
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   912
                         *   the if may hurt more than the additional
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   913
                         *   memory cycles on some machines ...
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   914
                         */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   915
                        if (((INT)byteP & 1) == 0) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   916
                            /* aligned */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   917
                            ((unsigned short *)byteP)[0] = val;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   918
                        } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   919
#endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   920
                        {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   921
                            byteP[1] = val & 0xFF;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   922
                            byteP[0] = (val>>8) & 0xFF;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   923
                        }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   924
                    } else {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   925
                        /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   926
                         * least significant byte first (i.e i386/alpha order)
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   927
                         */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   928
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   929
                        ((unsigned short *)byteP)[0] = val;
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   930
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   931
# if defined(__LSBFIRST__)
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   932
                        /*
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   933
                         * mhmh to be measured:
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   934
                         *   the if may hurt more than the additional
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   935
                         *   memory cycles on some machines ...
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   936
                         */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   937
                        if (((INT)byteP & 1) == 0) {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   938
                            /* aligned */
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   939
                            ((unsigned short *)byteP)[0] = val;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   940
                        } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   941
# endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   942
                        {
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   943
                            byteP[0] = val & 0xFF;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   944
                            byteP[1] = (val>>8) & 0xFF;
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   945
                        }
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   946
#endif
19048
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   947
                    }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   948
                    RETURN ( value );
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   949
                }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   950
            }
0929f428048d #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18966
diff changeset
   951
        }
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   952
    }
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
   953
immutable: ;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   954
%}.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   955
    ^ super unsignedInt16At:index put:value MSB:msb
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   956
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   957
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   958
     |b|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   959
     b := ByteArray new:8.
19350
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   960
     b unsignedInt16At:1 put:16r0102 MSB:false.
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   961
     b unsignedInt16At:3 put:16r0304 MSB:false.
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   962
     b unsignedInt16At:5 put:16r0102 MSB:true.
6eb57a6369be #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 19178
diff changeset
   963
     b unsignedInt16At:7 put:16r0304 MSB:true.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   964
     b inspect
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   965
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   966
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   967
11502
64d1cb6c2062 changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 11265
diff changeset
   968
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   969
!ByteArray methodsFor:'comparing'!
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   970
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   971
= aByteArray
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   972
    "Compare the receiver with the argument and return true if the
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   973
     receiver is equal to the argument (i.e. has the same size and elements).
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   974
     Otherwise return false."
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   975
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   976
%{  /* NOCONTEXT */
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   977
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   978
    int l1, l2;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   979
    REGISTER OBJ s = aByteArray;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   980
    unsigned char *cp1, *cp2;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   981
    OBJ cls;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   982
    OBJ myCls;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   983
    INT addrDelta;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   984
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   985
    if (s == self) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   986
	RETURN ( true );
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   987
    }
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   988
    if (! __isNonNilObject(s)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   989
	RETURN ( false );
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   990
    }
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   991
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   992
    cls = __qClass(s);
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   993
    myCls = __qClass(self);
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   994
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   995
    if (cls == myCls) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   996
	l2 = __byteArraySize(s);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   997
	l1 = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   998
	if (l1 != l2) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   999
	    RETURN ( false );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1000
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1001
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1002
	cp1 = __byteArrayVal(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1003
	cp2 = __byteArrayVal(s);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1004
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1005
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1006
	 * care for instances of subclasses ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1007
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1008
	if (cls != ByteArray) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1009
	    int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1010
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1011
	    cp2 += n;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1012
	    cp1 += n;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1013
	    l1 -= n;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1014
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1015
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1016
	addrDelta = cp2 - cp1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1017
	while (l1 >= (sizeof(unsigned INT) * 4)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1018
	    if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1019
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1020
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1021
	    if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1022
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1023
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1024
	    if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1025
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1026
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1027
	    if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1028
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1029
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1030
	    l1 -= sizeof(unsigned INT)*4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1031
	    cp1 += sizeof(unsigned INT)*4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1032
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1033
	while (l1 >= sizeof(unsigned INT)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1034
	    if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1035
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1036
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1037
	    l1 -= sizeof(unsigned INT);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1038
	    cp1 += sizeof(unsigned INT);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1039
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1040
	if (l1 >= sizeof(unsigned short)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1041
	    if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1042
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1043
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1044
	    l1 -= sizeof(unsigned short);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1045
	    cp1 += sizeof(unsigned short);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1046
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1047
	while (l1) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1048
	    if (*cp1 != *(cp1+addrDelta)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1049
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1050
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1051
	    l1--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1052
	    cp1++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1053
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1054
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1055
	RETURN (true);
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1056
    }
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1057
%}.
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1058
    ^ super = aByteArray
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1059
! !
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1060
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1061
!ByteArray methodsFor:'converting'!
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1062
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1063
asByteArray
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1064
    "return the receiver as a byteArray"
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1065
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1066
    "could be an instance of a subclass..."
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1067
    self class == ByteArray ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1068
	^ self
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1069
    ].
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1070
    ^ super asByteArray
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1071
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1072
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1073
     'hello world' asByteArray
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1074
     #(1 2 3 4 5 6 7) asByteArray
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1075
     #(1 2 256 4 5 6 7) asByteArray
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1076
    "
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1077
!
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1078
12453
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1079
asImmutableByteArray
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1080
    "return a write-protected copy of myself"
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1081
19178
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1082
    |copy|
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1083
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1084
    copy := self copy.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1085
    copy class == ByteArray ifTrue:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1086
        ^ copy changeClassTo:ImmutableByteArray.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1087
    ] ifFalse:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1088
        ^ self shouldNotImplement.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1089
    ].
12453
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1090
!
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1091
23925
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1092
asImmutableCollection
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1093
    "return a write-protected copy of myself"
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1094
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1095
    ^ self asImmutableByteArray
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1096
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1097
    "Created: / 15-03-2019 / 13:48:05 / Stefan Vogel"
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1098
!
fcde2f1eefbe #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23800
diff changeset
  1099
12276
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1100
asInteger
19397
8962f82110e1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19350
diff changeset
  1101
    "convert myself to an unsigned integer - the first byte is most significant.
12276
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1102
     This is also in Squeak."
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1103
16795
6ceacf5daa62 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16741
diff changeset
  1104
    ^ self asIntegerMSB:true
12276
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1105
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1106
    "
19397
8962f82110e1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19350
diff changeset
  1107
        #[ 2 ] asInteger hexPrintString
8962f82110e1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19350
diff changeset
  1108
        #[ 16r1 16r2 ] asInteger hexPrintString
8962f82110e1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19350
diff changeset
  1109
        #[4 0 0 0 0 0 0 0] asInteger hexPrintString
12276
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1110
    "
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1111
!
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1112
12621
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1113
asIntegerMSB:isMSBFirst
19397
8962f82110e1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19350
diff changeset
  1114
    "convert myself to an unsigned integer - the first byte is most significant.
12621
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1115
     This is also in Squeak."
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1116
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1117
    ^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed
12621
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1118
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1119
    "
19178
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1120
        (#[ 2 ] asIntegerMSB:true) hexPrintString
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1121
        (#[ 16r1 16r2 ] asIntegerMSB:true) hexPrintString
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1122
        (#[ 16r1 16r2 ] asIntegerMSB:false) hexPrintString
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1123
        (#[4 0 0 0 0 0 0 0 0 0 0 0] asIntegerMSB:true) hexPrintString
12621
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1124
    "
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1125
!
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1126
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1127
asPackedString
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1128
    "ST-80 compatibility: encode the receiver into an ascii String
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1129
     with 6bits encoded per character. Each group of 6 bits is encoded
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1130
     as a corresponding character (32+value) and the resulting string
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1131
     is returned. The resulting string is always a multiple of 4 (since
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1132
     24 is the lcm of 6 and 8) and the number of remaining characters is
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1133
     encoded in the last character.
16799
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1134
     ST-80 uses this encoding for Images...
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1135
     This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421.
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1136
     PS: I don't like it ;-)
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1137
     See also: fromPackedString: - the reverse operation"
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1138
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1139
    |outStream
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1140
     index     "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1141
     nextIndex "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1142
     stop      "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1143
     n         "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1144
     mod       "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1145
     cpl|
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1146
18584
ee039e582133 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 17535
diff changeset
  1147
    outStream := WriteStream on:(String new:((self size + 2) * 4 // 3)).
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1148
    index := 1.
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1149
    stop := self size.
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1150
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1151
    stop > 100 ifTrue:[
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1152
	"/ cg:
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1153
	"/ initial lineBreak
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1154
	outStream cr.
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1155
    ].
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1156
    cpl := 0.
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1157
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1158
    [index <= stop] whileTrue:[
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1159
	"take 3 source bytes"
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1160
	n := (self at:index) bitShift:16.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1161
	(index < stop) ifTrue:[
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1162
	    nextIndex := index + 1.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1163
	    n := n bitOr:((self at:nextIndex) bitShift:8).
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1164
	    (nextIndex < stop) ifTrue:[
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1165
		n := n bitOr:(self at:(index + 2)).
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1166
	    ].
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1167
	].
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1168
	index := index + 3.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1169
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1170
	"took me a while to find that one out ..."
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1171
	n := n bitXor:16r820820.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1172
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1173
	outStream nextPut:(Character value:((n bitShift:-18) bitAnd:16r3F) + 32).
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1174
	outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1175
	outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1176
	outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1177
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1178
	"/ cg:
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1179
	"/ lineBreak after every 120 characters
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1180
	"/ fromPackedString will ignore those
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1181
	cpl := cpl + 4.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1182
	cpl >= 120 ifTrue:[
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1183
	    outStream cr.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1184
	    cpl := 0.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1185
	].
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1186
    ].
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1187
    (mod := stop \\ 3) ~~ 0 ifTrue:[
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1188
	outStream backStep.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1189
	outStream nextPut:(Character value:(mod + 96)).
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1190
    ].
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1191
    ^ outStream contents
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1192
16799
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1193
    "
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1194
     #[ 16r00 16r01 16r02 16r04 16r08 16r10 16r20 16r40 16r80 ] asPackedString
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1195
    "
11676875b9fe class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16795
diff changeset
  1196
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1197
    "Modified: 12.11.1996 / 15:45:02 / cg"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1198
!
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1199
19178
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1200
asSignedByteArray
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1201
    "return the receiver as a signed byteArray.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1202
     elements > 127 are converted to negative numbers."
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1203
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1204
    |cls|
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1205
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1206
    cls := self class.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1207
    "could be an instance of a subclass..."
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1208
    (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1209
        ^ self copy changeClassTo:SignedByteArray.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1210
    ].
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1211
    ^ super asSignedByteArray
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1212
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1213
    "
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1214
     'hello world' asSignedByteArray
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1215
     #[1 2 3 4 5 6 7] asSignedByteArray
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1216
     #[1 2 129 4 5 6 7] asSignedByteArray
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1217
    "
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1218
!
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1219
20137
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1220
asString
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1221
    "speed up string conversions"
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1222
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1223
    |size cls|
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1224
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1225
    cls := self class.
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1226
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1227
    (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1228
        size := self size.
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1229
        ^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1.
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1230
    ].
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1231
    ^ super asString.
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1232
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1233
    "
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1234
      #[16r41 16r42 16r43] asString
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1235
      #[16r41 16r42 16r43] asImmutableByteArray asString
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1236
    "
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1237
!
b89a5898c3d2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20071
diff changeset
  1238
17377
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
  1239
beImmutable
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
  1240
    "make myself write-protected"
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
  1241
20519
da1c421ea59c #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20306
diff changeset
  1242
    super beImmutable.
19178
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1243
    self class == ByteArray ifTrue:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1244
        self changeClassTo:ImmutableByteArray.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1245
    ] ifFalse:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1246
        self shouldNotImplement.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1247
    ].
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1248
!
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1249
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1250
beSigned
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1251
    "make mayself signed.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1252
     elements > 127 are converted to negative numbers."
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1253
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1254
    self class == ByteArray ifTrue:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1255
        self changeClassTo:SignedByteArray.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1256
    ] ifFalse:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1257
        self shouldNotImplement.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1258
    ].
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1259
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1260
    "
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1261
        #[ 1 2 3 128 255] copy beSigned
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1262
    "
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1263
!
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1264
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1265
beUnsigned
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  1266
    "that's what I am (but I don't know if this is true for subclasses."
19178
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1267
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1268
    self class == ByteArray ifTrue:[
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1269
        ^ self.
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1270
    ].
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  1271
    self shouldNotImplement.
19178
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1272
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1273
    "
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1274
        #[ 1 2 3 128 255] copy beUnsigned
0c97c5cfb7df #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19134
diff changeset
  1275
    "
17377
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
  1276
!
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
  1277
4807
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1278
decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1279
    "given a literalEncoding in the receiver,
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1280
     create & return the corresponding object.
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1281
     The inverse operation to #literalArrayEncoding."
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1282
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1283
    ^ self
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1284
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1285
!
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1286
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1287
literalArrayEncoding
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1288
    "encode myself as an array literal, from which a copy of the receiver
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1289
     can be reconstructed with #decodeAsLiteralArray."
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1290
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  1291
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  1292
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  1293
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1294
	^ self
11063
ca134030dff4 changed #literalArrayEncoding: self is onlz ok for realByteArrays
fm
parents: 11010
diff changeset
  1295
    ].
ca134030dff4 changed #literalArrayEncoding: self is onlz ok for realByteArrays
fm
parents: 11010
diff changeset
  1296
    ^ super literalArrayEncoding
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1297
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1298
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1299
     #[1 2 3] literalArrayEncoding
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1300
    "
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1301
! !
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1302
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1303
!ByteArray methodsFor:'copying'!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1304
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1305
copy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1306
    "redefined for a bit more speed"
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1307
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1308
    self class == ByteArray ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1309
	^ self copyFrom:1 to:(self size)
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1310
    ].
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1311
    ^ super copy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1312
!
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1313
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1314
copyFrom:start to:stop
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1315
    "return the subcollection starting at index start, anInteger and ending
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1316
     at stop, anInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1317
     - reimplemented here for speed"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1318
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1319
%{  /* NOCONTEXT */
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1320
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1321
    REGISTER unsigned char *srcp;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1322
    REGISTER unsigned char *dstp;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1323
    REGISTER int count;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1324
    int len, index1, index2, sz;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1325
    OBJ newByteArray;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1326
12466
353502b2baa9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12453
diff changeset
  1327
    if (__isByteArrayLike(self)
249
claus
parents: 221
diff changeset
  1328
     && __bothSmallInteger(start, stop)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1329
	len = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1330
	index1 = __intVal(start);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1331
	index2 = __intVal(stop);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1332
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1333
	if ((index1 <= index2) && (index1 > 0)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1334
	    if (index2 <= len) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1335
		count = index2 - index1 + 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1336
		__PROTECT_CONTEXT__
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1337
		sz = OHDR_SIZE + count;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1338
		__qNew(newByteArray, sz);       /* OBJECT ALLOCATION */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1339
		__UNPROTECT_CONTEXT__
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1340
		if (newByteArray != nil) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1341
		    __InstPtr(newByteArray)->o_class = ByteArray;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1342
		    __qSTORE(newByteArray, ByteArray);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1343
		    dstp = __ByteArrayInstPtr(newByteArray)->ba_element;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1344
		    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
2648
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1345
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1346
#ifdef bcopy4
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1347
		    if (((unsigned INT)srcp & 3) == ((unsigned INT)dstp & 3)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1348
			int nW;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1349
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1350
			/* copy unaligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1351
			while (count && (((unsigned INT)srcp & 3) != 0)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1352
			    *dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1353
			    count--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1354
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1355
			if (count) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1356
			    /* copy aligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1357
			    nW = count >> 2;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1358
			    if (count & 3) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1359
				nW++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1360
			    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1361
			    bcopy4(srcp, dstp, nW);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1362
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1363
			RETURN ( newByteArray );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1364
		    }
2648
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1365
#endif /* bcopy4 */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
  1366
#if __POINTER_SIZE__ == 8
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1367
		    if (((unsigned INT)srcp & 7) == ((unsigned INT)dstp & 7)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1368
			int nW;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1369
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1370
			/* copy unaligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1371
			while (count && (((unsigned INT)srcp & 7) != 0)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1372
			    *dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1373
			    count--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1374
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1375
			/* copy aligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1376
			while (count >= 8) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1377
			    ((unsigned INT *)dstp)[0] = ((unsigned INT *)srcp)[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1378
			    dstp += 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1379
			    srcp += 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1380
			    count -= 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1381
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1382
			/* copy remaining part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1383
			while (count) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1384
			    *dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1385
			    count--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1386
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1387
			RETURN ( newByteArray );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1388
		    }
4943
8e51d34f2b3a slightly tuned #copyFrom:to: and #replaceBytesFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
  1389
#endif /* bcopy4 */
2648
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1390
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1391
#ifdef FAST_MEMCPY
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1392
		    bcopy(srcp, dstp, count);
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1393
#else
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1394
		    while (count--) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1395
			*dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1396
		    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1397
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1398
		    RETURN ( newByteArray );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1399
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1400
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1401
	}
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1402
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1403
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1404
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1405
     fall back in case of non-integer index or out-of-bound index;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1406
     will eventually lead to an out-of-bound signal raise
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1407
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1408
    ^ super copyFrom:start to:stop
4941
7674fdddb1db better byteArray copy on Intel
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1409
7674fdddb1db better byteArray copy on Intel
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1410
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1411
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:1 to:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1412
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1413
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1414
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:11
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1415
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1416
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:9
4941
7674fdddb1db better byteArray copy on Intel
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1417
    "
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1418
!
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1419
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1420
shallowCopy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1421
    "redefined for a bit more speed"
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1422
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1423
    self class == ByteArray ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1424
	^ self copyFrom:1 to:(self size)
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1425
    ].
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1426
    ^ super shallowCopy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1427
!
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1428
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1429
symbolFrom:start to:stop
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1430
    "make a symbol from the characters of the subcollection starting
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1431
     at index start, anInteger and ending at stop, anInteger.
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1432
     This saves us garbage and character copying."
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1433
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1434
    |sym|
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1435
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1436
%{  /* STACK:1024 */
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1437
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1438
    REGISTER unsigned char *srcp;
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1439
    REGISTER unsigned char *endp;
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1440
    REGISTER int count;
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1441
    int len, index1, index2;
4086
4b3a61a4e35d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
  1442
    unsigned char scratchBuffer[1024], savec;
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1443
12466
353502b2baa9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12453
diff changeset
  1444
    if (__isByteArrayLike(self) && __bothSmallInteger(start, stop)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1445
	len = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1446
	index1 = __intVal(start);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1447
	index2 = __intVal(stop);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1448
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1449
	if ((index1 <= index2) && (index1 > 0) && (index2 <= len)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1450
	    count = index2 - index1 + 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1451
	    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1452
	    if (index2 < len) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1453
		/* temporarily stuff in a '\0' */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1454
		endp = srcp + count + 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1455
		savec = *endp;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1456
		*endp = '\0';
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1457
		sym = __MKSYMBOL(srcp, 0);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1458
		/* must refetch endp (in case of a GC */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1459
		endp = __ByteArrayInstPtr(self)->ba_element + index1 + count;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1460
		*endp = savec;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1461
	    } else {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1462
		/* not enough space for '\0', copy the bytes */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1463
		if (count < sizeof(scratchBuffer)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1464
		    bcopy(srcp, scratchBuffer, count);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1465
		    scratchBuffer[count] = '\0';
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1466
		    sym = __MKSYMBOL(scratchBuffer, 0);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1467
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1468
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1469
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1470
	if (sym != nil)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1471
	    RETURN(sym);
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1472
    }
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1473
%}.
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1474
    "
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1475
     fall back in case of non-integer index or out-of-bound index
4086
4b3a61a4e35d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
  1476
     or not enough stack-memory available;
4b3a61a4e35d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
  1477
     may eventually lead to an out-of-bound signal raise
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1478
    "
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1479
    ^ (super copyFrom:start to:stop) asString asSymbol
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1480
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1481
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1482
    "
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1483
     'abcdefghijklmnop' symbolFrom:1 to:3
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1484
     'abcdefghijklmnop' symbolFrom:3 to:16
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1485
     'abcdefghijklmnop' symbolFrom:3 to:17
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1486
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1487
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1488
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4128
diff changeset
  1489
!ByteArray methodsFor:'filling & replacing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1490
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1491
from:start to:stop put:aNumber
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1492
    "fill part of the receiver with aNumber.
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1493
     - reimplemented here for speed"
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1494
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1495
%{  /* NOCONTEXT */
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1496
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1497
    REGISTER unsigned char *dstp;
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1498
    REGISTER int count, value;
249
claus
parents: 221
diff changeset
  1499
    int len, index1, index2;
claus
parents: 221
diff changeset
  1500
    OBJ cls;
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1501
249
claus
parents: 221
diff changeset
  1502
    if (__isSmallInteger(aNumber)
1002
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
  1503
     && __bothSmallInteger(start, stop)
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
  1504
     && __isBytes(self)) {
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1505
	len = __byteArraySize(self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1506
	index1 = __intVal(start);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1507
	index2 = __intVal(stop);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1508
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1509
	dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1510
	if ((cls = __qClass(self)) != @global(ByteArray)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1511
	    int nInst;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1512
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1513
	    nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1514
	    dstp += nInst;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1515
	    len -= nInst;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1516
	}
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1517
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1518
	value = __intVal(aNumber);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1519
	if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1520
	 && (index1 <= index2)
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1521
	 && (index1 > 0)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1522
	    if (index2 <= len) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1523
		count = index2 - index1 + 1;
2579
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1524
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1525
#ifdef memset4
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1526
		if (count > 20) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1527
		    /* fill unaligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1528
		    while (((unsigned INT)dstp & 3) != 0) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1529
			*dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1530
			count--;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1531
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1532
		    /* fill aligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1533
		    {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1534
			int n4 = count & ~3;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1535
			int v4, nW;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1536
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1537
			v4 = (value << 8) | value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1538
			v4 = (v4 << 16) | v4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1539
			nW = n4>>2;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1540
			memset4(dstp, v4, nW);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1541
			count -= n4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1542
			dstp += n4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1543
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1544
		    while (count--) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1545
			*dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1546
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1547
		    RETURN (self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1548
		}
2579
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1549
#endif /* memset4 */
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1550
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1551
#if (__POINTER_SIZE__ == 8)
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1552
		{
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1553
		    INT v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1554
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1555
		    v8 = (value << 8) | value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1556
		    v8 = (v8 << 16) | v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1557
		    v8 = (v8 << 32) | v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1558
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1559
		    /* fill unaligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1560
		    while ((count > 0) && (((unsigned INT)dstp & 3) != 0)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1561
			*dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1562
			count--;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1563
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1564
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1565
		    if ((count >= 4) && (((unsigned INT)dstp & 7) != 0)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1566
			((unsigned int *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1567
			dstp += 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1568
			count -= 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1569
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1570
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1571
		    /* fill aligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1572
		    while (count >= 8) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1573
			((unsigned INT *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1574
			dstp += 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1575
			count -= 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1576
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1577
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1578
		    /* fill rest */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1579
		    if (count >= 4) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1580
			((unsigned int *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1581
			dstp += 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1582
			count -= 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1583
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1584
		    if (count >= 2) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1585
			((unsigned short *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1586
			dstp += 2;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1587
			count -= 2;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1588
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1589
		    if (count) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1590
			*dstp = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1591
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1592
		    RETURN (self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1593
		}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1594
#endif /* 64bit */
4945
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1595
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1596
#ifdef FAST_MEMSET
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1597
		memset(dstp, value, count);
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1598
#else
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1599
# ifdef __UNROLL_LOOPS__
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1600
		while (count >= 8) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1601
		    dstp[0] = dstp[1] = dstp[2] = dstp[3] =
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1602
		    dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1603
		    dstp += 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1604
		    count -= 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1605
		}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1606
# endif /* __UNROLL_LOOPS__ */
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1607
		while (count--) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1608
		    *dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1609
		}
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1610
#endif
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1611
		RETURN (self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1612
	    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1613
	}
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1614
    }
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1615
%}.
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1616
    "
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1617
     fall back in case of non-integer index or out-of-bound index/value;
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1618
     will eventually lead to an out-of-bound signal raise
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1619
    "
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1620
    ^ super from:start to:stop put:aNumber
4945
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1621
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1622
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1623
     (ByteArray new:10) from:1 to:10 put:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1624
     (ByteArray new:20) from:10 to:20 put:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1625
     (ByteArray new:20) from:1 to:10 put:1
4945
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1626
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1627
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1628
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1629
!ByteArray methodsFor:'image manipulation support'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1630
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1631
bitAndBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1632
    "replace bytes in the receiver with the result of a bitAnd operation.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1633
     Warning: this is a destructive operation - elements in the receiver are overwritten."
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1634
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1635
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitAnd:
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1636
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1637
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1638
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1639
	bitAndBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1640
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1641
	bitAndBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1642
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1643
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1644
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1645
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1646
bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:ruleSymbol
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1647
    "perform a special case of an aligned bitBlit operation.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1648
     Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1649
     of some logical operation, as specified by the ruleSymbol.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1650
     SourceBytes are fetched starting at sourceOffset.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1651
     Valid rule symbols are:
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1652
	#copy    - trivial;  same as replaceBytesFrom:to:with:startingAt:
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1653
	#bitXor: - xoring;   byte[dI] = byte[dI] bitXor:(srcByte[sI])
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1654
	#bitAnd: - anding;   byte[dI] = byte[dI] bitAnd:(srcByte[sI])
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1655
	#bitOr:  - oring;    byte[dI] = byte[dI] bitOr:(srcByte[sI])
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1656
	#+       - adding;   byte[dI] = (byte[dI] + (srcByte[sI])) mod: 256
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1657
	#-       - subtract; byte[dI] = (byte[dI] - (srcByte[sI])) mod: 256
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1658
     Warning: this is a destructive operation - elements in the receiver are overwritten.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1659
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1660
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1661
    |srcIdx|
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1662
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1663
%{
12466
353502b2baa9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12453
diff changeset
  1664
    if ((__isByteArrayLike(sourceBytes))
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1665
     && (__qClass(self) == ByteArray)
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1666
     && __isSmallInteger(dstStart)
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1667
     && __isSmallInteger(dstEnd)
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1668
     && __isSmallInteger(sourceStart)) {
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1669
	unsigned char *srcP = __ByteArrayInstPtr(sourceBytes)->ba_element;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1670
	unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1671
	int srcLen = __byteArraySize(sourceBytes);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1672
	int dstLen = __byteArraySize(self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1673
	int __srcStart = __intVal(sourceStart);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1674
	int __dstStart = __intVal(dstStart);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1675
	int count = __intVal(dstEnd) - __dstStart + 1;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1676
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1677
	if ((__dstStart >= 1)
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1678
	 && (__srcStart >= 1)
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1679
	 && ((__dstStart + count - 1) <= dstLen)
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1680
	 && ((__srcStart + count - 1) <= srcLen)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1681
	    srcP += __srcStart - 1;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1682
	    dstP += __dstStart - 1;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1683
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1684
#define OP_LOOP_BYTES(OP) \
16621
ac0885c03e15 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16620
diff changeset
  1685
    while (count >= 4) {                                             \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1686
	(dstP[0]) OP (srcP[0]);                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1687
	(dstP[1]) OP (srcP[1]);                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1688
	(dstP[2]) OP (srcP[2]);                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1689
	(dstP[3]) OP (srcP[3]);                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1690
	srcP += 4;                                                   \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1691
	dstP += 4;                                                   \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1692
	count -= 4;                                                  \
16621
ac0885c03e15 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16620
diff changeset
  1693
    }                                                                \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1694
    while (count > 0) {                                              \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1695
	*dstP OP (*srcP);                                            \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1696
	srcP++;                                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1697
	dstP++;                                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1698
	count--;                                                     \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1699
    }
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1700
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1701
#define OP_LOOP(OP) \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1702
    while (count >= 16) {                                            \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1703
	((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]);    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1704
	((unsigned int *)dstP)[1] OP (((unsigned int *)srcP)[1]);    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1705
	((unsigned int *)dstP)[2] OP (((unsigned int *)srcP)[2]);    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1706
	((unsigned int *)dstP)[3] OP (((unsigned int *)srcP)[3]);    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1707
	srcP += 16;                                                  \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1708
	dstP += 16;                                                  \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1709
	count -= 16;                                                 \
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1710
    }                                                                \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1711
    while (count >= 4) {                                             \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1712
	((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]);    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1713
	srcP += 4;                                                   \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1714
	dstP += 4;                                                   \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1715
	count -= 4;                                                  \
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1716
    }                                                                \
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1717
    while (count > 0) {                                              \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1718
	*dstP OP (*srcP);                                            \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1719
	srcP++;                                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1720
	dstP++;                                                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1721
	count--;                                                     \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1722
    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1723
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1724
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1725
	    if (ruleSymbol == @symbol(bitXor:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1726
		OP_LOOP( ^= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1727
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1728
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1729
	    if (ruleSymbol == @symbol(bitXorNot:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1730
		OP_LOOP( ^=~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1731
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1732
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1733
	    if (ruleSymbol == @symbol(bitAnd:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1734
		OP_LOOP( &= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1735
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1736
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1737
	    if (ruleSymbol == @symbol(bitAndNot:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1738
		OP_LOOP( &=~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1739
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1740
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1741
	    if (ruleSymbol == @symbol(bitOr:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1742
		OP_LOOP( |= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1743
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1744
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1745
	    if (ruleSymbol == @symbol(bitOrNot:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1746
		OP_LOOP( |=~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1747
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1748
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1749
	    if (ruleSymbol == @symbol(copy)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1750
		OP_LOOP( = )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1751
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1752
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1753
	    if (ruleSymbol == @symbol(copyNot)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1754
		OP_LOOP( =~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1755
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1756
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1757
	    if (ruleSymbol == @symbol(+)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1758
		OP_LOOP_BYTES( += )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1759
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1760
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1761
	    if (ruleSymbol == @symbol(-)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1762
		OP_LOOP_BYTES( -= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1763
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1764
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1765
	}
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1766
    }
5549
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1767
#undef OP_LOOP_BYTES
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1768
#undef OP_LOOP
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1769
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1770
%}.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1771
    ruleSymbol == #copy ifTrue:[
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1772
	self replaceFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1773
	^ self
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1774
    ].
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1775
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1776
    srcIdx := sourceStart.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1777
    dstStart to:dstEnd do:[:dstIdx |
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1778
	self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:(sourceBytes at:srcIdx)).
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1779
	srcIdx := srcIdx + 1.
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1780
    ].
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1781
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1782
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1783
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1784
	bitBlitBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1785
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1786
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1787
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1788
	bitBlitBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#bitAnd:
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1789
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1790
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1791
     #[255 0 0 0 0 0 0 0]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1792
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1793
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1794
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#+
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  1795
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1796
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1797
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1798
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#copyNot
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1799
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1800
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1801
	bitBlitBytesFrom:1 to:8 with:(1 to:8) startingAt:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1802
    "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1803
!
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1804
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1805
bitBlitBytesFrom:dstStart to:dstEnd withConstant:sourceByte rule:ruleSymbol
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1806
    "perform a special case of an aligned bitBlit operation.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1807
     Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1808
     of some logical operation, as specified by the ruleSymbol.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1809
     Valid rule symbols are:
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1810
	#copy    - trivial;  same as from:to:put:
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1811
	#bitXor: - xoring;   byte[dI] = byte[dI] bitXor:sourceConst
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1812
	#bitAnd: - anding;   byte[dI] = byte[dI] bitAnd:sourceConst
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1813
	#bitOr:  - oring;    byte[dI] = byte[dI] bitOr:sourceConst
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1814
	#+       - adding;   byte[dI] = (byte[dI] + sourceConst) mod: 256
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1815
	#-       - subtract; byte[dI] = (byte[dI] - sourceConst) mod: 256
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1816
     Warning: this is a destructive operation - elements in the receiver are overwritten.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1817
    "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1818
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1819
    |srcIdx|
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1820
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1821
%{
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1822
    if ((__qClass(self) == ByteArray)
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1823
     && __isSmallInteger(dstStart)
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1824
     && __isSmallInteger(dstEnd)
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1825
     && __isSmallInteger(sourceByte)) {
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1826
	unsigned char srcByte = __intVal(sourceByte);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1827
	unsigned srcWord;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1828
	unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1829
	int dstLen = __byteArraySize(self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1830
	int __dstStart = __intVal(dstStart);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1831
	int count = __intVal(dstEnd) - __dstStart + 1;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1832
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1833
	srcWord = (srcByte << 8) | srcByte;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1834
	srcWord = (srcWord << 16) | srcWord;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1835
	if ((__dstStart >= 1)
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1836
	 && ((__dstStart + count - 1) <= dstLen)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1837
	    dstP += __dstStart - 1;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1838
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1839
#define OP_LOOP_BYTES(OP) \
16620
9db0a09c71c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15625
diff changeset
  1840
    while (count >= 4) {                         \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1841
	dstP[0] OP srcByte;                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1842
	dstP[1] OP srcByte;                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1843
	dstP[2] OP srcByte;                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1844
	dstP[3] OP srcByte;                      \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1845
	dstP += 4;                               \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1846
	count -= 4;                              \
16620
9db0a09c71c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15625
diff changeset
  1847
    }                                            \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1848
    while (count > 0) {                          \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1849
	*dstP OP srcByte;                        \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1850
	dstP++;                                  \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1851
	count--;                                 \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1852
    }
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1853
16620
9db0a09c71c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15625
diff changeset
  1854
#define OP_LOOP_INT32(OP) \
9db0a09c71c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15625
diff changeset
  1855
    while (count >= 16) {                        \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1856
	((unsigned int *)dstP)[0] OP srcWord;    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1857
	((unsigned int *)dstP)[1] OP srcWord;    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1858
	((unsigned int *)dstP)[2] OP srcWord;    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1859
	((unsigned int *)dstP)[3] OP srcWord;    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1860
	dstP += 16;                              \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1861
	count -= 16;                             \
16620
9db0a09c71c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15625
diff changeset
  1862
    }                                            \
9db0a09c71c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15625
diff changeset
  1863
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1864
#define OP_LOOP(OP) \
16620
9db0a09c71c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15625
diff changeset
  1865
    OP_LOOP_INT32(OP)                            \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1866
    while (count >= 4) {                         \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1867
	((unsigned int *)dstP)[0] OP srcWord;    \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1868
	dstP += 4;                               \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1869
	count -= 4;                              \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1870
    }                                            \
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1871
    while (count > 0) {                          \
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1872
	*dstP OP srcByte;                        \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1873
	dstP++;                                  \
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1874
	count--;                                 \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1875
    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1876
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1877
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1878
	    if (ruleSymbol == @symbol(bitXor:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1879
		OP_LOOP( ^= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1880
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1881
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1882
	    if (ruleSymbol == @symbol(bitXorNot:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1883
		OP_LOOP( ^=~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1884
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1885
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1886
	    if (ruleSymbol == @symbol(bitAnd:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1887
		OP_LOOP( &= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1888
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1889
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1890
	    if (ruleSymbol == @symbol(bitAndNot:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1891
		OP_LOOP( &=~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1892
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1893
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1894
	    if (ruleSymbol == @symbol(bitOr:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1895
		OP_LOOP( |= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1896
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1897
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1898
	    if (ruleSymbol == @symbol(bitOrNot:)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1899
		OP_LOOP( |=~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1900
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1901
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1902
	    if (ruleSymbol == @symbol(copy)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1903
		OP_LOOP( = )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1904
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1905
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1906
	    if (ruleSymbol == @symbol(copyNot)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1907
		OP_LOOP( =~ )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1908
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1909
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1910
	    if (ruleSymbol == @symbol(+)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1911
		OP_LOOP_BYTES( += )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1912
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1913
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1914
	    if (ruleSymbol == @symbol(-)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1915
		OP_LOOP_BYTES( -= )
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1916
		RETURN (self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1917
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1918
	}
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1919
    }
5549
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1920
#undef OP_LOOP_BYTES
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1921
#undef OP_LOOP
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1922
%}.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1923
    ruleSymbol == #copy ifTrue:[
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1924
	self from:dstStart to:dstEnd put:sourceByte.
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1925
	^ self
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1926
    ].
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1927
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1928
    dstStart to:dstEnd do:[:dstIdx |
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1929
	self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:sourceByte).
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1930
    ].
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1931
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1932
    "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1933
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1934
	bitBlitBytesFrom:1 to:3 withConstant:1 rule:#bitXor:
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1935
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1936
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitXor:
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1937
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1938
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitAnd:
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1939
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1940
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1941
     #[255 0 0 0 0 0 0 0]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1942
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1943
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1944
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1945
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1946
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#-
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1947
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1948
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#copyNot
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1949
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1950
     #[1 2 3 4 5 6 7 8]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  1951
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1952
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1953
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1954
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1955
bitOrBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1956
    "replace bytes in the receiver with the result of a bitOr operation.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1957
     Warning: this is a destructive operation - elements in the receiver are overwritten."
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1958
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1959
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitOr:
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1960
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1961
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1962
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1963
	bitOrBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1964
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1965
	bitOrBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1966
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1967
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1968
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1969
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1970
bitXorBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1971
    "replace bytes in the receiver with the result of an bitXor operation.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1972
     Warning: this is a destructive operation - elements in the receiver are overwritten."
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1973
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1974
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitXor:
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1975
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1976
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1977
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1978
	bitXorBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1979
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1980
	bitXorBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1981
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1982
	bitXorBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1983
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1984
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1985
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1986
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  1987
compressPixels:nBitsPerPixel width:width height:height into:aByteArray mapping:aMapByteArray
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1988
    "given the receiver with 8-bit pixels, compress them into aByteArray
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1989
     with nBitsPerPixel-depth pixels. The width/height-arguments are needed
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1990
     to allow for any padding. On the fly, the source bytes are translated
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1991
     using aMapByteArray (if non-nil).
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1992
     Notice that smalltalk indexing begins at 1; thus the map-index for a byte
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1993
     value of n is found in map at:(n + 1).
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1994
     Output bits are filled left-to right, i.e. the first byte in the input
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1995
     corresponds to the high bit(s) if the first byte in the input.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1996
     This method can be used to convert 8-bit image data to mono, 2-bit and 4-bit
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1997
     bitmaps.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1998
     It can also be used to compress byte-arrays into bitArrays."
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1999
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2000
%{  /* NOCONTEXT */
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2001
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2002
    REGISTER unsigned char *src, *dst;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2003
    REGISTER int wrun;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2004
    unsigned char *dstNext;
1472
abaa73dc0e9a check for destination overrun
Claus Gittinger <cg@exept.de>
parents: 1459
diff changeset
  2005
    unsigned char *dstEnd;
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2006
    int bytesPerRow, mask, shift0, shift;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2007
    int w, h, hrun;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2008
    int srcBytes, dstBytes;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2009
    int bitsPerPixel;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2010
    int bits;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2011
    int ncells;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2012
    unsigned char *map;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2013
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2014
    if ((__qClass(self) == @global(ByteArray))
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2015
     && (__qClass(aByteArray) == @global(ByteArray))
249
claus
parents: 221
diff changeset
  2016
     && __isSmallInteger(nBitsPerPixel)
claus
parents: 221
diff changeset
  2017
     && __bothSmallInteger(height, width)) {
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2018
	if ((aMapByteArray != nil)
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2019
	 && (__Class(aMapByteArray) == @global(ByteArray))) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2020
	    map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2021
	} else {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2022
	    map = (unsigned char *)0;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2023
	}
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2024
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2025
	bitsPerPixel = __intVal(nBitsPerPixel);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2026
	w = __intVal(width);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2027
	h = __intVal(height);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2028
	src = __ByteArrayInstPtr(self)->ba_element;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2029
	dst = __ByteArrayInstPtr(aByteArray)->ba_element;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2030
	dstEnd = dst + __byteArraySize(aByteArray);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2031
	switch (bitsPerPixel) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2032
	    case 1:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2033
		mask = 0x01;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2034
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2035
	    case 2:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2036
		mask = 0x03;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2037
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2038
	    case 4:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2039
		mask = 0x0F;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2040
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2041
	    case 8:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2042
		mask = 0xFF;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2043
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2044
	    default:
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2045
		console_printf("invalid depth in compressPixels\n");
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2046
		goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2047
	}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2048
	if (map) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2049
	    /*
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2050
	     * if a map is present, it must have entries for
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2051
	     * all possible byte-values (i.e. its size must be >= 256)
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2052
	     */
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2053
	    if ((__qSize(aMapByteArray) - OHDR_SIZE) < 256) {
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2054
		console_printf("invalid map in compressPixels\n");
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2055
		goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2056
	    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2057
	}
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2058
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2059
	bytesPerRow = (w * bitsPerPixel + 7) / 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2060
	dstBytes = bytesPerRow * h;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2061
	srcBytes = w * h;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2062
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2063
	if ((__byteArraySize(self) >= srcBytes)
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2064
	 && (__byteArraySize(aByteArray) >= dstBytes)) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2065
	    for (hrun=h; hrun; hrun--) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2066
		dstNext = dst + bytesPerRow;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2067
		bits = 0; shift = 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2068
		if (map) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2069
		    for (wrun=w; wrun; wrun--) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2070
			bits = (bits << bitsPerPixel) | (map[*src++] & mask);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2071
			shift -= bitsPerPixel;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2072
			if (shift == 0) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2073
			    if (dst == dstEnd) goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2074
			    *dst++ = bits;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2075
			    bits = 0; shift = 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2076
			}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2077
		    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2078
		} else {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2079
		    for (wrun=w; wrun; wrun--) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2080
			bits = (bits << bitsPerPixel) | (*src++ & mask);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2081
			shift -= bitsPerPixel;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2082
			if (shift == 0) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2083
			    if (dst == dstEnd) goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2084
			    *dst++ = bits;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2085
			    bits = 0; shift = 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2086
			}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2087
		    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2088
		}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2089
		if (shift != 8) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2090
		    if (dst == dstEnd) goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2091
		    *dst = bits;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2092
		}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2093
		dst = dstNext;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2094
	    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2095
	    RETURN ( self );
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2096
	}
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2097
    }
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2098
fail: ;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2099
%}.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2100
    self primitiveFailed
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2101
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2102
    "Example1:
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2103
     compress 1 byte-per-pixel bitmap to 1-bit-per-pixel bitmap
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2104
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2105
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2106
     |inBits outBits|
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2107
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2108
     inBits := #[0 0 0 0 1 1 1 1
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2109
		 0 0 1 1 0 0 1 1
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2110
		 0 1 0 1 0 1 0 1
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2111
		 1 1 1 1 0 0 0 0].
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2112
     outBits := ByteArray new:4.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2113
     inBits compressPixels:1 width:8 height:4
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2114
		    into:outBits mapping:nil.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2115
     outBits inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2116
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2117
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2118
    "Example2:
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2119
     compress byte-array into a bitArray, translating 99 to 0-bits,
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2120
     and 176 to 1-bits. (just a stupid example)
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2121
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2122
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2123
     |inBits outBits map|
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2124
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2125
     inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2126
     map := ByteArray new:256.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2127
     map at:176+1 put:1.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2128
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2129
     outBits := ByteArray new:2.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2130
     inBits compressPixels:1 width:16 height:1
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2131
		    into:outBits mapping:map.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2132
     outBits inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2133
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2134
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2135
    "Example3:
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2136
     compress byte-array into a bitArray, translating everything below 128 to 0-bits,
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2137
     and 128 to 255 to 1-bits.99 to 0-bits (another stupid example)
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2138
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2139
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2140
     |inBits outBits map|
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2141
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2142
     inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2143
     map := ByteArray new:256.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2144
     map atAll:(128+1 to:255+1) put:1.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2145
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2146
     outBits := ByteArray new:2.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2147
     inBits compressPixels:1 width:16 height:1
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2148
		    into:outBits mapping:map.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2149
     outBits inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2150
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2151
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2152
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2153
expandPixels:nBitsPerPixel width:width height:height into:aByteArray mapping:aMapByteArray
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2154
    "given the receiver with nBitsPerPixel-depth pixels, expand them into
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2155
     aByteArray with 8-bit pixels. The width/height-arguments are needed
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2156
     to skip any padded src-bits. On the fly, the destination pixels
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2157
     are translated using aMapByteArray (if non-nil).
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2158
     Input bits are read left-to right, i.e. the first byte in the output
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2159
     corresponds to the high bit(s) in the inputs first byte.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2160
     This is used to display mono, 2-bit and 4-bit bitmaps on grey-scale/color
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2161
     machines. With nBitsPerPixel==8, this is a translate operation.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2162
     Notice that smalltalk indexing begins at 1; thus the map-index for a byte
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2163
     value of n is found in map at:(n + 1).
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2164
     It can also be used to expand bit-arrays into byteArrays.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2165
     This method is specialized for ByteArray arguments - it will not handle
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2166
     anything else."
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2167
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2168
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2169
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2170
    REGISTER unsigned char *src, *dst;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2171
    REGISTER int wrun;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2172
    unsigned char *srcNext;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2173
    int bytesPerRow, mask, shift0, shift;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2174
    int w, h, hrun;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2175
    int srcBytes, dstBytes;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2176
    int bitsPerPixel;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2177
    int bits;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2178
    int ncells;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2179
    unsigned char *map;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2180
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2181
    if ((__qClass(self) == @global(ByteArray))
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2182
     && (__qClass(aByteArray) == @global(ByteArray))
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2183
     && __isSmallInteger(nBitsPerPixel)
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2184
     && __bothSmallInteger(height, width)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2185
	if ((aMapByteArray != nil)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2186
	 && (__Class(aMapByteArray) == @global(ByteArray))) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2187
	    map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2188
	} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2189
	    map = (unsigned char *)0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2190
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2191
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2192
	bitsPerPixel = __intVal(nBitsPerPixel);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2193
	w = __intVal(width);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2194
	h = __intVal(height);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2195
	src = __ByteArrayInstPtr(self)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2196
	dst = __ByteArrayInstPtr(aByteArray)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2197
	switch (bitsPerPixel) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2198
	    case 1:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2199
		mask = 0x01;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2200
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2201
	    case 2:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2202
		mask = 0x03;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2203
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2204
	    case 4:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2205
		mask = 0x0F;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2206
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2207
	    case 8:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2208
		mask = 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2209
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2210
	    default:
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2211
		console_printf("expandPixels: invalid depth\n");
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2212
		goto fail;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2213
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2214
	ncells = mask + 1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2215
	if (map) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2216
	    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2217
	     * if a map is present, it must have the correct size
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2218
	     * (i.e. 2 raisedTo:nBitsPerPixel)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2219
	     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2220
	    if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells) {
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2221
		console_printf("expandPixels: invalid map\n");
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2222
		goto fail;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2223
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2224
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2225
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2226
	bytesPerRow = (w * bitsPerPixel + 7) / 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2227
	shift0 = 8 - bitsPerPixel;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2228
	srcBytes = bytesPerRow * h;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2229
	dstBytes = w * h;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2230
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2231
	if ((__byteArraySize(self) >= srcBytes)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2232
	 && (__byteArraySize(aByteArray) >= dstBytes)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2233
	    for (hrun=h; hrun; hrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2234
		srcNext = src + bytesPerRow;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2235
		shift = shift0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2236
		if (map) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2237
		    if (shift0 == 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2238
			/* translate only */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2239
			for (wrun=w; wrun; wrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2240
			    bits = *src++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2241
			    *dst++ = map[bits];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2242
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2243
		    } else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2244
			for (wrun=w; wrun; wrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2245
			    if (shift == shift0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2246
				bits = *src++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2247
			    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2248
			    *dst++ = map[(bits >> shift) & mask];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2249
			    shift -= bitsPerPixel;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2250
			    if (shift < 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2251
				shift = shift0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2252
			    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2253
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2254
		    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2255
		} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2256
		    for (wrun=w; wrun; wrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2257
			if (shift == shift0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2258
			    bits = *src++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2259
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2260
			*dst++ = (bits >> shift) & mask;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2261
			shift -= bitsPerPixel;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2262
			if (shift < 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2263
			    shift = shift0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2264
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2265
		    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2266
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2267
		src = srcNext;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2268
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2269
	    RETURN ( self );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2270
	}
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2271
	console_printf("expandPixels: buffer size: self:%"_ld_" expect at least:%"_ld_"\n",
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2272
		(INT)(__byteArraySize(self)), (INT)srcBytes);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2273
	console_printf("expandPixels: buffer size: arg:%"_ld_" expect at least:%"_ld_"\n",
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2274
		(INT)(__byteArraySize(aByteArray)), (INT)dstBytes);
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2275
    }
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2276
    console_printf("expandPixels: invalid args\n");
1527
af119b16aa16 better handle the translate-only case in #expandPixels:
ca
parents: 1505
diff changeset
  2277
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2278
fail: ;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2279
%}.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2280
    self primitiveFailed
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2281
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2282
    "Example1:
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2283
     expand 1-bit-per-pixel bitmap into a 1byte-per-pixel byteArray
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2284
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2285
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2286
     |inBits outBits|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2287
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2288
     inBits := #[2r11110000
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2289
		 2r11001100
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2290
		 2r01010101
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2291
		 2r00001111].
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2292
     outBits := ByteArray new:(8*4).
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2293
     inBits expandPixels:1 width:8 height:4
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2294
		    into:outBits mapping:nil.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2295
     outBits inspect
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2296
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2297
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2298
    "Example2:
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2299
     expand bit-array into a byteArray, translating 0-bits to 99,
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2300
     1-bits to 176. (just a stupid example)
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2301
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2302
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2303
     |inBits outBits|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2304
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2305
     inBits := #[2r11110000 2r11001100].
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2306
     outBits := ByteArray new:16.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2307
     inBits expandPixels:1 width:16 height:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2308
		    into:outBits mapping:#[99 176].
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2309
     outBits inspect
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2310
    "
4978
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2311
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2312
    "This Can also be used to extract nibbles ..."
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2313
    "
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2314
     |inBits outBits|
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2315
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2316
     inBits := #[ 16r12 16r34 16r56 16r78 16r9A 16rBC 16rDE 16rF0 ].
4978
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2317
     outBits := ByteArray new:(inBits size * 2).
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2318
     inBits expandPixels:4 width:outBits size height:1 into:outBits mapping:nil.
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2319
     outBits inspect
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2320
    "
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2321
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2322
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2323
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2324
invert
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2325
    "invert all bytes - used with image manipulations
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2326
     written as a primitive for speed.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2327
     Q: is this really needed ?"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2328
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2329
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2330
    REGISTER unsigned char *dst;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2331
    REGISTER unsigned long *ldst;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2332
    REGISTER int cnt;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2333
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2334
    if (__qClass(self) == @global(ByteArray)) {
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2335
	cnt = __byteArraySize(self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2336
	dst = __ByteArrayInstPtr(self)->ba_element;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2337
	if (((INT)dst & (sizeof(long)-1)) == 0) { // aligned
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2338
	    ldst = (unsigned long *)dst;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2339
	    while (cnt >= (sizeof(long))*4) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2340
		ldst[0] = ~(ldst[0]);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2341
		ldst[1] = ~(ldst[1]);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2342
		ldst[2] = ~(ldst[2]);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2343
		ldst[3] = ~(ldst[3]);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2344
		ldst += 4;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2345
		cnt -= (sizeof(long))*4;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2346
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2347
	    while (cnt >= sizeof(long)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2348
		*ldst = ~(*ldst);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2349
		ldst++;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2350
		cnt -= sizeof(long);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2351
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2352
	    dst = (unsigned char *)ldst;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2353
	}
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2354
	while (cnt--) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2355
	    *dst = ~(*dst);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2356
	    dst++;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2357
	}
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2358
	RETURN ( self );
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2359
    }
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2360
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  2361
    self bitBlitBytesFrom:1 to:self size withConstant:16rFF rule:#bitXor:
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2362
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2363
    "
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2364
     #[1 2 3 4 5 6 7 8 9 10] copy invert
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2365
     #[1 2 3 4 5 6 7 8 9 10] copy
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2366
	bitBlitBytesFrom:1 to:10 withConstant:16rFF rule:#bitXor:
16621
ac0885c03e15 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16620
diff changeset
  2367
ac0885c03e15 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16620
diff changeset
  2368
     |l|
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2369
     l := ByteArray fromHexString:'0102030405060708090a0b0c0d0e0f1112131415161718191a1b1c1d1e1f'.
16621
ac0885c03e15 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16620
diff changeset
  2370
     Time millisecondsToRun:[
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2371
	1000000 timesRepeat:[ l invert ].
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2372
     ]
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2373
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2374
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2375
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2376
reverse
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2377
    "reverse the order of my elements inplace -
7338
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7245
diff changeset
  2378
     WARNING: this is a destructive operation, which modifies the receiver.
19619
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2379
              Please use reversed (with a 'd' at the end) for a functional version.
7338
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7245
diff changeset
  2380
     Written as a primitive for speed on image manipulations (mirror)"
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2381
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2382
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2383
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2384
    REGISTER unsigned char *p1, *p2;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2385
    REGISTER int cnt;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2386
    REGISTER unsigned t;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2387
    OBJ cls;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2388
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2389
    if (__qClass(self) == @global(ByteArray)) {
19619
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2390
        cnt = __byteArraySize(self);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2391
        p1 = __ByteArrayInstPtr(self)->ba_element;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2392
        p2 = p1 + cnt - 1;
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2393
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2394
#if defined(__BSWAP)
19619
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2395
        /*
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2396
         * can we use the bswap instruction ?
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2397
         * notice - not all CPUs have it (the HAS_BSWAP checks this).
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2398
         */
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2399
        if (__HAS_BSWAP()
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2400
         && ((cnt & 3) == 0)) {
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2401
            unsigned int *ip1, *ip2;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2402
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2403
            ip1 = (unsigned int *)p1;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2404
            ip2 = (unsigned int *)(p2 - 3);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2405
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2406
            ip2 -= 7;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2407
            while (ip1 <= ip2) {
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2408
                int t1, t2;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2409
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2410
                t1 = ip1[0];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2411
                t2 = ip2[7];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2412
                ip2[7] = __BSWAP(t1);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2413
                ip1[0] = __BSWAP(t2);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2414
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2415
                t1 = ip1[1];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2416
                t2 = ip2[6];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2417
                ip2[6] = __BSWAP(t1);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2418
                ip1[1] = __BSWAP(t2);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2419
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2420
                t1 = ip1[2];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2421
                t2 = ip2[5];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2422
                ip2[5] = __BSWAP(t1);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2423
                ip1[2] = __BSWAP(t2);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2424
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2425
                t1 = ip1[3];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2426
                t2 = ip2[4];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2427
                ip2[4] = __BSWAP(t1);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2428
                ip1[3] = __BSWAP(t2);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2429
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2430
                ip1 += 4;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2431
                ip2 -= 4;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2432
            }
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2433
            ip2 += 7;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2434
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2435
            while (ip1 < ip2) {
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2436
                int t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2437
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2438
                t = __BSWAP(*ip1);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2439
                *ip1++ = __BSWAP(*ip2);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2440
                *ip2-- = t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2441
            }
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2442
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2443
            if (ip1 == ip2) {
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2444
                int t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2445
                t = *ip1;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2446
                t = __BSWAP(t);
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2447
                *ip1 = t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2448
            }
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2449
            RETURN ( self );
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2450
        }
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2451
#endif /* __BSWAP (i.e. __i386__ && __GNUC__) */
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2452
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2453
        p2 -= 7;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2454
        while (p1 <= p2) {
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2455
            t = p1[0];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2456
            p1[0] = p2[7];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2457
            p2[7] = t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2458
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2459
            t = p1[1];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2460
            p1[1] = p2[6];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2461
            p2[6] = t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2462
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2463
            t = p1[2];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2464
            p1[2] = p2[5];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2465
            p2[5] = t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2466
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2467
            t = p1[3];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2468
            p1[3] = p2[4];
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2469
            p2[4] = t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2470
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2471
            p1 += 4;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2472
            p2 -= 4;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2473
        }
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2474
        p2 += 7;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2475
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2476
        while (p1 < p2) {
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2477
            t = *p1;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2478
            *p1++ = *p2;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2479
            *p2-- = t;
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2480
        }
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2481
        RETURN ( self );
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2482
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2483
%}.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2484
    ^ super reverse
2585
6c25622320aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2579
diff changeset
  2485
6c25622320aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2579
diff changeset
  2486
    "
21736
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2487
     #[1 2 3 4 5] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2488
     #[] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2489
     #[1] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2490
     #[1 2] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2491
     #[1 2 3] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2492
     #[1 2 3 4] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2493
     #[1 2 3 4 5] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2494
     #[1 2 3 4 5 6] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2495
     #[1 2 3 4 5 6 7] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2496
     #[1 2 3 4 5 6 7 8] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2497
     #[1 2 3 4 5 6 7 8] copy reverseFrom:2 to:5
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2498
     #[1 2 3 4 5 6 7 8 9] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2499
     #[1 2 3 4 5 6 7 8 9 10] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2500
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2501
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] copy reverse
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2502
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] copy reverse
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2503
     (1 to:255) asByteArray reverse
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2504
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2505
     1 to:1024 do:[:i|
19619
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2506
        |bytes test rBytes|
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2507
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2508
        bytes := ((1 to:i) asArray collect:[:i | i bitAnd:255]) asByteArray.
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2509
        test := ((i to:1 by:-1) asArray collect:[:i | i bitAnd:255]) asByteArray.
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2510
        rBytes := bytes copy.
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2511
        rBytes reverse ~= test ifTrue:[
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2512
            self halt
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2513
        ].
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2514
        rBytes := bytes copy.
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2515
        rBytes reverse reverse ~= bytes ifTrue:[
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2516
            self halt
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2517
        ]
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2518
     ].
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2519
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2520
     Time millisecondsToRun:[
19619
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2521
        10000000 timesRepeat:[
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2522
            #[1 2 3 4 5 6 7 8] reverse
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2523
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2524
     ]
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2525
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2526
     |b|
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2527
     b := (0 to:255) asByteArray.
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2528
     Time millisecondsToRun:[
19619
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2529
        10000000 timesRepeat:[
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2530
            b reverse
beb60d40e286 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19563
diff changeset
  2531
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2532
     ]
2585
6c25622320aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2579
diff changeset
  2533
    "
21736
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2534
fc05f985abf2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21539
diff changeset
  2535
    "Modified (comment): / 01-05-2017 / 12:56:13 / cg"
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2536
!
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2537
22032
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2538
swap:i1 with:i2
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2539
   "spap the bytes at i1 and i2"
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2540
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2541
%{  /* NOCONTEXT */
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2542
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2543
    REGISTER unsigned char *p;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2544
    unsigned int __i1, __i2;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2545
    int sz;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2546
    unsigned int t;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2547
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2548
    if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) {
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2549
        __i1 = __intVal(i1) - 1;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2550
        __i2 = __intVal(i2) - 1;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2551
        sz = __byteArraySize(self);
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2552
        p = __ByteArrayInstPtr(self)->ba_element;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2553
        if ((__i1 < sz) && (__i2 < sz)) {
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2554
            t = p[__i1];
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2555
            p[__i1] = p[__i2];
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2556
            p[__i2] = t;
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2557
            RETURN ( self );
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2558
        }
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2559
    }
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2560
%}.
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2561
    ^ super swap:i1 with:i2 
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2562
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2563
    "
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2564
     #[1 2 3 4 5 6 7 8 9 10] copy swapIndex:1 and:10
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2565
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapIndex:5 and:6
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2566
    "
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2567
!
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  2568
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2569
swapBytes
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2570
    "swap bytes (of int16s) inplace -
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2571
     Expects that the receiver has an even number of bytes;
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2572
     if not, only the pairs excluding the last byte are swapped.
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2573
     written as a primitive for speed on image grabbing (if display order is different)."
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2574
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2575
%{  /* NOCONTEXT */
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2576
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2577
    REGISTER unsigned char *p;
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2578
    REGISTER int cnt;
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2579
    REGISTER unsigned t;
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2580
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2581
    if (__qClass(self) == @global(ByteArray)) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2582
        cnt = __byteArraySize(self);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2583
        cnt = cnt & ~1; /* make it even */
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2584
        p = __ByteArrayInstPtr(self)->ba_element;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2585
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2586
        while (cnt >= sizeof(INT)) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2587
            unsigned INT i = ((unsigned INT *)p)[0];
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2588
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2589
#if __POINTER_SIZE__ == 8
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2590
            i = ((i>>8) & 0x00FF00FF00FF00FF) | ((i & 0x00FF00FF00FF00FF) << 8);
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
  2591
#else
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2592
            i = ((i>>8) & 0x00FF00FF) | ((i & 0x00FF00FF) << 8);
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2593
#endif /* __POINTER_SIZE__ */
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2594
            ((unsigned INT *)p)[0] = i;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2595
            p += sizeof(INT);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2596
            cnt -= sizeof(INT);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2597
        }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2598
        while (cnt > 0) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2599
            unsigned short s;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2600
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2601
            s = ((unsigned short *)p)[0];
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2602
            s = (s >> 8) | (s << 8);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2603
            ((unsigned short *)p)[0] = s;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2604
            p += 2;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2605
            cnt -= 2;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2606
        }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2607
        RETURN ( self );
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2608
    }
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2609
%}.
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2610
    ^ super swapBytes "/ rubbish - there is no one currenly
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2611
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2612
    "
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2613
     #[1 2 3 4 5 6 7 8 9 10] copy swapBytes     -> #[2 1 4 3 6 5 8 7 10 9]
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2614
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes  -> #[2 1 4 3 6 5 8 7 10 9 11]
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2615
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] copy swapBytes
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2616
    "
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2617
!
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2618
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2619
swapLongs
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2620
    "swap long bytes inplace
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2621
     - any partial longs at the end are not swapped."
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2622
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2623
    self swapLongsFrom:1 to:self size
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2624
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2625
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2626
     #[1 2 3 4 5 6 7 8 9] copy swapLongs
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2627
     #[1 2 3 4 5 6 7 8 9 10] copy swapLongs
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2628
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapLongs
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2629
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy swapLongs
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2630
    "
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2631
!
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2632
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2633
swapLongsFrom:startIndex to:endIndex
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2634
    "swap longs (int32s) inplace
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2635
     - any partial longs at the end are not swapped.
4367
3d481db099ec oops - swapLongsFrom:to: was wrong
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2636
     Swapping is from startIndex to (exclusiv) endIndex;
3d481db099ec oops - swapLongsFrom:to: was wrong
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2637
     indexing starts at 1."
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2638
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2639
%{  /* NOCONTEXT */
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2640
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2641
    REGISTER unsigned char *p;
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2642
    REGISTER int limit;
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2643
    REGISTER unsigned t;
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2644
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2645
    if ((__qClass(self) == @global(ByteArray))
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2646
     && __isSmallInteger(startIndex)
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2647
     && __isSmallInteger(endIndex)) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2648
        int __idx = __intVal(startIndex);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2649
        int __endIdx = __intVal(endIndex);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2650
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2651
        limit = __byteArraySize(self);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2652
        if (__endIdx < limit) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2653
            limit = __endIdx;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2654
        }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2655
        p = __ByteArrayInstPtr(self)->ba_element;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2656
        p = p + __idx - 1;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2657
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2658
        limit = limit - 4 + 1;
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2659
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2660
#if defined(__BSWAP)
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2661
        /*
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2662
         * can we use the bswap instruction ?
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2663
         * notice - not all CPUs have it (the HAS_BSWAP checks this).
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2664
         */
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2665
        if (__HAS_BSWAP()
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2666
         && (((unsigned int)p & 3) == 0)) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2667
            unsigned int *ip;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2668
            ip = (unsigned int *)p;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2669
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2670
            while (__idx <= limit) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2671
                *ip = __BSWAP(*ip);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2672
                ip++;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2673
                __idx += 4;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2674
            }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2675
            RETURN (self);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2676
        }
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2677
#endif /* __BSWAP */
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2678
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2679
        while (__idx <= limit) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2680
            t = p[0];
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2681
            p[0] = p[3];
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2682
            p[3] = t;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2683
            t = p[1];
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2684
            p[1] = p[2];
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2685
            p[2] = t;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2686
            p += 4;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2687
            __idx += 4;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2688
        }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2689
        RETURN ( self );
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2690
    }
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2691
%}.
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2692
    ^ super swapLongsFrom:startIndex to:endIndex "/ rubbish - there is no one currenly
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2693
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2694
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2695
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2696
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:4
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2697
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:5
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2698
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:6
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2699
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2700
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2701
     #[1 2 3 4 5 6 7 8 9 10] copy swapLongsFrom:1 to:11
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2702
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapLongsFrom:1 to:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2703
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy swapLongsFrom:1 to:13
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2704
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:5 to:10
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2705
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2706
! !
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2707
10028
f43a291eabd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9659
diff changeset
  2708
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2709
!ByteArray methodsFor:'printing & storing'!
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2710
13078
7934a86b395b Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 12932
diff changeset
  2711
displayOn:aGCOrStream
1244
dc9dd731258c commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  2712
    "return a printed representation of the receiver for displaying"
dc9dd731258c commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  2713
21539
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2714
    |cls|
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2715
17535
44798ad63741 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 17433
diff changeset
  2716
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
21539
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2717
    "/ old ST80 means: draw-yourself on a GC.
18596
d6abf6a67de4 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 18584
diff changeset
  2718
    cls := self class.
d6abf6a67de4 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 18584
diff changeset
  2719
    ((cls == ByteArray or:[cls == ImmutableByteArray]) and:[aGCOrStream isStream]) ifTrue:[
21539
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2720
        self storeOn:aGCOrStream.
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2721
        ^ self
6513
d7bc1d1dab4b displayString fix for subclasses
Claus Gittinger <cg@exept.de>
parents: 6125
diff changeset
  2722
    ].
13078
7934a86b395b Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 12932
diff changeset
  2723
    ^ super displayOn:aGCOrStream
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2724
21539
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2725
    "Created: / 25-10-1995 / 13:33:26 / cg"
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2726
    "Modified: / 22-04-1996 / 12:54:06 / cg"
8533ab5cdbf5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21483
diff changeset
  2727
    "Modified (comment): / 22-02-2017 / 16:54:27 / cg"
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2728
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2729
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2730
printOn:aStream
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2731
    "append a printed representation to aStream"
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2732
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2733
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2734
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2735
    "/ care for subclasses
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2736
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2737
	aStream nextPutAll:'#['.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2738
	self
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2739
	    do:[:byte | byte printOn:aStream]
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2740
	    separatedBy:[aStream space].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2741
	aStream nextPut:$].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2742
	^ self
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2743
    ].
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2744
    ^ super printOn:aStream
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2745
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2746
    "
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2747
     #[1 2 3 4 5] printOn:Transcript
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2748
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2749
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2750
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2751
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2752
     #[1 2 3 4 5] printString
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2753
    "
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2754
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2755
    "Modified: / 12.9.1997 / 22:11:33 / cg"
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2756
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2757
!
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2758
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2759
printOn:aStream base:radix
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2760
    "append a printed representation to aStream in the given number base."
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2761
6125
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2762
    ^ self printOn:aStream base:radix showRadix:false
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2763
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2764
    "
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2765
     #[1 2 3 4 5] printOn:Transcript base:2
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2766
     'Hello World' printOn:Transcript base:2
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2767
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2768
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2769
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2770
     #[1 2 3 4 5] printString
6125
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2771
    "
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2772
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2773
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2774
    "Modified: / 31.10.2001 / 09:43:56 / cg"
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2775
!
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2776
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2777
printOn:aStream base:radix showRadix:showRadix
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2778
    "append a printed representation to aStream in the given number base."
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2779
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2780
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2781
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2782
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2783
	"/ care for subclasses
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2784
	aStream nextPutAll:'#['.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2785
	self
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2786
	    do:[:byte | byte printOn:aStream base:radix showRadix:showRadix]
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2787
	    separatedBy:[aStream space].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2788
	aStream nextPut:$].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2789
	^ self
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2790
    ].
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2791
    ^ self printOn:aStream
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2792
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2793
    "
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2794
     #[1 2 3 4 5] printOn:Transcript base:2
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2795
     'Hello World' printOn:Transcript base:2
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2796
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2797
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2798
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2799
     #[1 2 3 4 5] printString
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2800
    "
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2801
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2802
    "Modified: / 12.9.1997 / 22:11:33 / cg"
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2803
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
6125
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2804
    "Created: / 31.10.2001 / 09:43:41 / cg"
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2805
!
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2806
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2807
storeOn:aStream
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2808
    "append a printed representation from which the receiver can be
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2809
     reconstructed to aStream. (reimplemented to make it look better)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2810
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2811
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2812
21483
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2813
    cls := self class.
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2814
    (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2815
        "/ care for subclasses
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2816
        aStream nextPutAll:'#['.
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2817
        self
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2818
            do:[:byte | byte storeOn:aStream]
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2819
            separatedBy:[aStream space].
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2820
        aStream nextPut:$].
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2821
        ^ self
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2822
    ].
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2823
    ^ super storeOn:aStream
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2824
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2825
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2826
     #[1 2 3 4 5] storeOn:Transcript
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2827
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2828
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2829
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2830
     #[1 2 3 4 5] printString
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2831
    "
1082
b186a68fff0e category change
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  2832
21483
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2833
    "Modified: / 12-09-1997 / 22:11:33 / cg"
582158f616ff #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21465
diff changeset
  2834
    "Modified: / 17-02-2017 / 10:50:37 / stefan"
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2835
! !
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2836
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2837
!ByteArray methodsFor:'queries'!
1082
b186a68fff0e category change
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  2838
22933
715902b93fa8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22032
diff changeset
  2839
characterSize   
715902b93fa8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22032
diff changeset
  2840
    "answer the size in bits of my largest character (actually only 7, 8, 16 or 32).
715902b93fa8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22032
diff changeset
  2841
     Needed in case someone writes bytes to a CharacterWriteStream (comanche response)"
715902b93fa8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22032
diff changeset
  2842
715902b93fa8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22032
diff changeset
  2843
    ^ 8
715902b93fa8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22032
diff changeset
  2844
!
715902b93fa8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22032
diff changeset
  2845
16804
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2846
containsNon7BitAscii
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2847
    "return true, if any byte in the receiver has the 7th bit on.
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2848
     This my look as a too specific operation to be put here,
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2849
     put it is very helpful for UTF8 string reading (Java class reader),
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2850
     to quickly determine, if UTF8 decoding is needed or not.
18596
d6abf6a67de4 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 18584
diff changeset
  2851
     As most strings in a class file are in fact only containing 7bit ascii,
16804
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2852
     this should speedup class file reading considerably"
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2853
16805
e1f4f10936c0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16804
diff changeset
  2854
%{  /* NOCONTEXT */
16804
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2855
    REGISTER unsigned char *cp;
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2856
    REGISTER unsigned char *endP;
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2857
18611
fca966d5e383 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 18596
diff changeset
  2858
    if (__isByteArrayLike(self)) {
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2859
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2860
	endP = cp + __byteArraySize(self);
16806
575f0e271998 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16805
diff changeset
  2861
#if __POINTER_SIZE__ == 8
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2862
	while (cp+8 < endP) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2863
	    if ( ((unsigned INT *)cp)[0] & 0x8080808080808080) RETURN( true );
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2864
	    cp += 8;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2865
	}
16806
575f0e271998 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16805
diff changeset
  2866
#endif
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2867
	while (cp+4 < endP) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2868
	    if ( ((unsigned int *)cp)[0] & 0x80808080) RETURN( true );
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2869
	    cp += 4;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2870
	}
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2871
	while (cp < endP) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2872
	    if (*cp++ & 0x80) RETURN( true );
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2873
	}
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  2874
	RETURN ( false );
16804
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2875
    }
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2876
%}
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2877
.
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2878
    ^ self contains:[:b | b bitTest:16r80].
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2879
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2880
    "
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2881
     #[1 2 3 1 2 3 1 2 127 ] containsNon7BitAscii
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2882
     #[1 2 3 1 2 3 1 2 250 251 250 251 255] containsNon7BitAscii
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2883
    "
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2884
!
8b7dfe6e80b0 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 16799
diff changeset
  2885
18966
3bc73a4cdae6 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18665
diff changeset
  2886
containsNon8BitElements
3bc73a4cdae6 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18665
diff changeset
  2887
    "return true, if one of my elements is larger than a single byte.
3bc73a4cdae6 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18665
diff changeset
  2888
     Per definition not."
3bc73a4cdae6 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18665
diff changeset
  2889
3bc73a4cdae6 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18665
diff changeset
  2890
    ^ false.
3bc73a4cdae6 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18665
diff changeset
  2891
!
3bc73a4cdae6 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18665
diff changeset
  2892
23710
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2893
isEmpty
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2894
    "return true if the receiver is empty (i.e. if size == 0)
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2895
     Redefined here for performance"
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2896
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2897
%{  /* NOCONTEXT */
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2898
#ifndef __SCHTEAM__
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2899
    if (__isByteArrayLike(self)) {
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2900
        RETURN ( (__byteArraySize(self) == 0) ? true : false);
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2901
    }
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2902
#endif /* ! __SCHTEAM__ */
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2903
%}.
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2904
    ^ self size == 0
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2905
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2906
    "Created: / 16-02-2017 / 15:02:03 / stefan"
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2907
!
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2908
20306
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2909
isValidElement:anObject
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2910
    "return true, if I can hold this kind of object"
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2911
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2912
    ^ anObject isInteger
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2913
    and:[ (anObject >= self class minVal)
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2914
    and:[ (anObject <= self class maxVal) ]]
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2915
!
07ff17265c6b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20137
diff changeset
  2916
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2917
max
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2918
    "return the maximum value in the receiver -
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2919
     redefined to speedup image processing and sound-player
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2920
     (which need a fast method for this on byteArrays)"
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2921
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2922
%{  /* NOCONTEXT */
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2923
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2924
    REGISTER unsigned char *cp;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2925
    REGISTER int index, max;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2926
    int len;
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2927
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2928
    if (__isByteArrayLike(self)) {
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2929
        max = 0;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2930
        index = 0;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2931
        len = __qSize(self) - OHDR_SIZE;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2932
        cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2933
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2934
        if (len > 0) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2935
            while (++index <= len) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2936
                unsigned int byte;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2937
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2938
                byte = *cp;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2939
                cp++;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2940
                if (byte > max) {
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2941
                    max = byte;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2942
                    if (byte == 255) break;
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2943
                }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2944
            }
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2945
            RETURN ( __mkSmallInteger(max) );
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2946
        }
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2947
    }
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2948
%}.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2949
    ^ super max
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2950
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2951
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2952
     #[1 2 3 1 2 3 1 2 19] max
19414
4cf7fc881b10 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19397
diff changeset
  2953
     #[] max
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2954
    "
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  2955
!
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2956
23710
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2957
notEmpty
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2958
    "return true if the receiver is not empty (i.e. if size ~~ 0)
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2959
     Redefined here for performance"
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2960
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2961
%{  /* NOCONTEXT */
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2962
#ifndef __SCHTEAM__
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2963
    if (__isByteArrayLike(self)) {
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2964
        RETURN ( (__byteArraySize(self) != 0) ? true : false);
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2965
    }
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2966
#endif /* ! __SCHTEAM__ */
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2967
%}.
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2968
    ^ self size ~~ 0
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2969
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2970
    "Created: / 16-02-2017 / 15:02:36 / stefan"
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2971
!
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  2972
19645
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2973
startsWith:aByteOrByteArray
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2974
    "return true, if the receiver starts with something, aStringOrChar.
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2975
     If the argument is empty, true is returned.
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2976
     Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:,
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2977
     which are both inconsistent w.r.t. an empty argument."
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2978
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2979
%{  /* NOCONTEXT */
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2980
    int len1, len2;
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2981
    REGISTER unsigned char *src1, *src2;
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2982
    unsigned char c;
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2983
    REGISTER OBJ slf = self;
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2984
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2985
    if (__qIsByteArrayLike(slf) &&__isByteArrayLike(aByteOrByteArray)) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2986
        src1 = __byteArrayVal(slf);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2987
        src2 = __byteArrayVal(aByteOrByteArray);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2988
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2989
        if (src1[0] != src2[0]) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2990
            if (__qSize(aByteOrByteArray) == OHDR_SIZE) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2991
                RETURN (true);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2992
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2993
            RETURN ( false );
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2994
        }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2995
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2996
        len1 = __qSize(slf);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2997
        len2 = __qSize(aByteOrByteArray);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2998
        if (len1 < len2) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  2999
            RETURN ( false );
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3000
        }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3001
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3002
# ifdef UINT64
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3003
        while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3004
            if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3005
                RETURN (false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3006
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3007
            len2 -= sizeof(UINT64);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3008
            src1 += sizeof(UINT64);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3009
            src2 += sizeof(UINT64);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3010
        }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3011
# else
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3012
#  ifdef __UNROLL_LOOPS__
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3013
        while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3014
            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3015
                RETURN (false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3016
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3017
            if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3018
                RETURN (false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3019
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3020
            if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3021
                RETURN (false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3022
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3023
            if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3024
                RETURN (false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3025
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3026
            len2 -= sizeof(INT)*4;
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3027
            src1 += sizeof(INT)*4;
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3028
            src2 += sizeof(INT)*4;
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3029
        }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3030
#  endif /* __UNROLL_LOOPS__ */
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3031
# endif /* UINT64 */
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3032
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3033
        while (len2 > (OHDR_SIZE+sizeof(INT))) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3034
            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3035
                RETURN (false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3036
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3037
            len2 -= sizeof(INT);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3038
            src1 += sizeof(INT);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3039
            src2 += sizeof(INT);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3040
        }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3041
19764
9a79f79d50c4 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 19645
diff changeset
  3042
        for ( ; len2 > OHDR_SIZE; len2--) {
19645
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3043
            if (*src1++ != *src2++) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3044
                RETURN (false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3045
            }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3046
        }    
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3047
        RETURN (true);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3048
    }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3049
    if (__isSmallInteger(aByteOrByteArray)) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3050
        int val = __intVal(aByteOrByteArray);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3051
        if (__byteArraySize(slf) > 0) {
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3052
            RETURN ( (__byteArrayVal(slf)[0] == val) ? true : false);
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3053
        }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3054
        RETURN ( false );
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3055
    }
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3056
%}.
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3057
    ^ super startsWith:aByteOrByteArray
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3058
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3059
    "
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3060
     #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 1 2 3 4 5]
19764
9a79f79d50c4 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 19645
diff changeset
  3061
     #[1 2 3 4] startsWith:#[ 1 3 4 5]
19645
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3062
     #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 0 1 2 3 4 5]
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3063
     #[1 2 3 4 5 6 7 8 9 10] startsWith:#(1 2 3 4 5)
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3064
     #[1 2 3 4 5 6 7 8 9 10] startsWith:1
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3065
     #[1 2 3 4 5 6 7 8 9 10] startsWith:2
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3066
    "
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3067
!
053a5232234d #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19619
diff changeset
  3068
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3069
usageCounts
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3070
    "return an array filled with value-counts -
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3071
     This is needed in the bitmap/image classes to get info on color usage.
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3072
     (i.e. to build up a histogram of color usage within an image)."
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3073
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3074
    |counts|
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3075
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3076
    counts := Array basicNew:256.
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3077
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3078
%{  /* STACK: 2000 */
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3079
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3080
    REGISTER unsigned char *cp;
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3081
    REGISTER int nByte;
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3082
    REGISTER int index;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3083
    INT icounts[256];
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3084
12768
4c56c6dd923d Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents: 12719
diff changeset
  3085
    if (__isByteArrayLike(self) && __isArray(counts)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3086
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3087
	 * zero counts
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3088
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3089
	for (index=0; index<256; index++) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3090
	    icounts[index] = 0;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3091
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3092
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3093
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3094
	 * count
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3095
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3096
	nByte = __qSize(self) - OHDR_SIZE;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3097
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3098
	while (nByte--) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3099
	    icounts[*cp++]++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3100
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3101
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3102
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3103
	 * make it real counts
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3104
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3105
	for (index=0; index<256; index++) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3106
	    __ArrayInstPtr(counts)->a_element[index] = __mkSmallInteger(icounts[index]);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3107
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3108
	RETURN ( counts );
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3109
    }
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3110
%}
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3111
.
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3112
    self primitiveFailed
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3113
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3114
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3115
     #[1 2 3 1 2 3 1 2 250 251 250 251 255] usageCounts
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3116
    "
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3117
!
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3118
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  3119
usedValues
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  3120
    "return a new ByteArray with all used values (actually a kind of Set);
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3121
     This is needed specially in the bitmap/Imageclasses to find used colors
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3122
     of an image."
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3123
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  3124
%{  /* STACK: 400 */
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3125
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3126
    REGISTER unsigned char *cp;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3127
    unsigned char *endp;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  3128
    REGISTER int len;
2890
fa0418a0f896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2866
diff changeset
  3129
    OBJ result;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3130
    union {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3131
	unsigned char flags[256];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3132
	int toForceAlignmentOfFlags;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3133
    } f;
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3134
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3135
#ifdef TO_BE_MEASURED
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3136
    int coverage = 0;
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3137
#endif
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3138
12768
4c56c6dd923d Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents: 12719
diff changeset
  3139
    if (__isByteArrayLike(self)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3140
	memset(f.flags, 0, sizeof(f.flags));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3141
	len = __qSize(self) - OHDR_SIZE;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3142
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3143
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3144
	/* for each used byte, set flag */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3145
	while (len > 0) {
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3146
#ifdef TO_BE_MEASURED
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3147
	    unsigned  byte;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3148
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3149
	    byte = *cp;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3150
	    if (! f.flags[byte]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3151
		f.flags[byte] = 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3152
		coverage++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3153
		if (coverage == 256) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3154
		    /* no need to scan rest */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3155
		    break;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3156
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3157
	    }
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3158
#else
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3159
	    f.flags[*cp] = 1;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3160
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3161
	    cp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3162
	    len--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3163
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3164
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3165
	/* count 1's */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3166
	len = 0;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3167
	for (cp=f.flags, endp=f.flags+256; cp < endp;) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3168
	    if ( *((unsigned int *)cp)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3169
		if (cp[0]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3170
		if (cp[1]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3171
		if (cp[2]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3172
		if (cp[3]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3173
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3174
	    cp += 4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3175
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3176
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3177
	/* create ByteArray of used values */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3178
	result = __BYTEARRAY_UNINITIALIZED_NEW_INT(len);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3179
	if (result) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3180
	    cp = __ByteArrayInstPtr(result)->ba_element;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3181
	    for (len=0; len < 256; len++) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3182
		if (f.flags[len])
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3183
		    *cp++ = len;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3184
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3185
	    RETURN ( result );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  3186
	}
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3187
    }
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3188
%}.
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  3189
    ^ self asIdentitySet asByteArray
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3190
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3191
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3192
     #[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3193
    "
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3194
! !
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  3195
22032
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  3196
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3197
!ByteArray methodsFor:'searching'!
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3198
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3199
indexOf:aByte startingAt:start
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3200
    "return the index of the first occurrence of the argument, aByte
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3201
     in the receiver starting at start, anInteger; return 0 if not found.
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3202
     - reimplemented here for speed"
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3203
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3204
%{  /* NOCONTEXT */
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3205
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3206
    REGISTER unsigned char *cp;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3207
    REGISTER INT index;
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3208
    REGISTER int byteValue;
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3209
    REGISTER int len;
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3210
    OBJ cls;
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3211
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3212
    if (__isSmallInteger(aByte) &&__isBytes(self)) {
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3213
	byteValue = __intVal(aByte);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3214
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3215
	if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3216
	    /*
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3217
	     * searching for something which cannot be found
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3218
	     */
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3219
	    RETURN ( __mkSmallInteger(0) );
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3220
	}
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3221
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3222
	if (__isSmallInteger(start)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3223
	    index = __intVal(start);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3224
	    len = __byteArraySize(self);
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3225
	    cp = __ByteArrayInstPtr(self)->ba_element;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3226
	    if ((cls = __qClass(self)) != @global(ByteArray)) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3227
		int nInst;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3228
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3229
		nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3230
		cp += nInst;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3231
		len -= nInst;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3232
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3233
	    cp += index - 1;
14382
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  3234
#ifdef __UNROLL_LOOPS__
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3235
	    while ((index+4) < len) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3236
		if (cp[0] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3237
		if (cp[1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3238
		if (cp[2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3239
		if (cp[3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3240
		index += 4;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3241
		cp += 4;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3242
	    }
14382
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  3243
#endif
18655
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3244
	    while (index <= len) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3245
		if (*cp == byteValue) {
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3246
		    RETURN ( __mkSmallInteger(index) );
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3247
		}
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3248
		index++;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3249
		cp++;
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3250
	    }
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3251
	    RETURN ( __mkSmallInteger(0) );
57469de23fac INT prinitng
Claus Gittinger <cg@exept.de>
parents: 18611
diff changeset
  3252
	}
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3253
    }
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3254
%}.
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3255
    ^ super indexOf:aByte startingAt:start
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3256
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3257
    "
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  3258
     #[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0 startingAt:1
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3259
    "
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3260
! !
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3261
22032
88b043aeda8c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21736
diff changeset
  3262
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3263
!ByteArray methodsFor:'testing'!
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3264
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3265
isByteArray
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3266
    "return true, if the receiver is some kind of bytearray;
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3267
     true is returned here - the method is redefined from Object."
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3268
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3269
    ^ true
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3270
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3271
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3272
!
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3273
23800
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3274
isIntegerArray
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3275
    "return true if the receiver has integer elements.
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3276
     These are Byte- and Integer arrays; both signed and unsigned"
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3277
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3278
    ^ true
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3279
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3280
    "Created: / 02-03-2019 / 23:11:00 / Claus Gittinger"
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3281
!
0f0470940b33 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23710
diff changeset
  3282
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3283
isLiteral
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3284
    "return true, if the receiver can be used as a literal constant in ST syntax
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3285
     (i.e. can be used in constant arrays)"
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3286
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3287
    "/ no, simply returning true here is a mistake:
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3288
    "/ it could be a subclass of ByteArray
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3289
    "/ (of which the compiler does not know at all ...)
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3290
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3291
    ^ self class == ByteArray
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3292
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3293
    "Modified: 22.4.1996 / 12:55:30 / cg"
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3294
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3295
23710
e340c313eeea #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22933
diff changeset
  3296
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3297
!ByteArray class methodsFor:'documentation'!
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3298
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3299
version
18584
ee039e582133 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 17535
diff changeset
  3300
    ^ '$Header$'
12091
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
  3301
!
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
  3302
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
  3303
version_CVS
18584
ee039e582133 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 17535
diff changeset
  3304
    ^ '$Header$'
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3305
! !
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  3306