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