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