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