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