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