--- a/ByteArray.st Mon Mar 08 12:14:12 2021 +0000
+++ b/ByteArray.st Mon Aug 31 17:20:18 2020 +0100
@@ -43,17 +43,22 @@
ByteArrays store integers in the range 0..255.
In contrast to normal arrays (which store pointers to their elements),
byteArrays store the values in a dense & compact way.
- ByteArrays can be used to hold the data for bitmaps, images and other bulk data.
+ ByteArrays can be used to hold the data for bitmaps, images and other bulk data
+ (instances are returned eg. when reading a binary file or socket).
ByteArrays are also used to store the bytecode-instructions of an
interpreted method and are used as superclass for Strings.
ByteArrays can be used as literals i.e. you can enter ByteArray-constants
- as #[ element1 element2 .... elementN] and also use byteArray constants
- as elements in a constant array.
- As in: #( #[1 1 1] #[2 2 2] #[3 3 3])
+ as
+ #[ element1 element2 .... elementN]
+
+ and also use byteArray constants as elements in a constant array, as in:
+ #( #[1 1 1] #[2 2 2] #[3 3 3])
+
+ Notice that the compilers are configured to create instances of ImmutableByteArray for literals.
If you have to communicate structure-data (in the C-sense) with external
- programs/data-bases, see a companion class (Structure).
+ programs/data-bases, see companion classes (Structure, ExternalBytes and ExternalStructure).
It allows the definition of subclasses of ByteArray, which transparently fetch
and store C-structure fields.
@@ -68,6 +73,7 @@
Claus Gittinger
[See also:]
+ ImmutableByteArray
Array CharacterArray String
"
! !
@@ -165,10 +171,6 @@
^ self basicNew:anInteger
! !
-
-
-
-
!ByteArray class methodsFor:'queries'!
elementByteSize
@@ -203,7 +205,6 @@
^ 0
! !
-
!ByteArray methodsFor:'Compatibility-Squeak'!
bitXor:aByteArray
@@ -229,6 +230,13 @@
"
! !
+!ByteArray methodsFor:'Compatibility-VW'!
+
+asByteString
+ "same as asString, for visualworks compatibility"
+
+ ^ self asString
+! !
!ByteArray methodsFor:'accessing'!
@@ -727,7 +735,7 @@
unsignedInt16At:index MSB:msb
"return the 2-bytes starting at index as an (unsigned) Integer.
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
- LSB-first (i.e. low 8-bits at lower byte index) if its false.
+ LSB-first (i.e. low 8-bits at lower byte index) if it's false.
Notice:
the index is a byte index; thus, this allows for unaligned access to
words on any boundary.
@@ -796,6 +804,8 @@
}
%}.
^ super unsignedInt16At:index MSB:msb
+
+ "Modified (comment): / 13-02-2017 / 19:56:53 / cg"
!
unsignedInt16At:index put:value
@@ -962,7 +972,6 @@
"
! !
-
!ByteArray methodsFor:'comparing'!
= aByteArray
@@ -973,86 +982,87 @@
%{ /* NOCONTEXT */
int l1, l2;
- REGISTER OBJ s = aByteArray;
unsigned char *cp1, *cp2;
OBJ cls;
OBJ myCls;
INT addrDelta;
- if (s == self) {
- RETURN ( true );
+ if (aByteArray == self) {
+ RETURN ( true );
}
- if (! __isNonNilObject(s)) {
- RETURN ( false );
+ if (! __isNonNilObject(aByteArray)) {
+ RETURN ( false );
}
- cls = __qClass(s);
+ cls = __qClass(aByteArray);
myCls = __qClass(self);
- if (cls == myCls) {
- l2 = __byteArraySize(s);
- l1 = __byteArraySize(self);
- if (l1 != l2) {
- RETURN ( false );
- }
-
- cp1 = __byteArrayVal(self);
- cp2 = __byteArrayVal(s);
-
- /*
- * care for instances of subclasses ...
- */
- if (cls != ByteArray) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- cp2 += n;
- cp1 += n;
- l1 -= n;
- }
-
- addrDelta = cp2 - cp1;
- while (l1 >= (sizeof(unsigned INT) * 4)) {
- if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
- RETURN (false);
- }
- if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
- RETURN (false);
- }
- if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
- RETURN (false);
- }
- if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
- RETURN (false);
- }
- l1 -= sizeof(unsigned INT)*4;
- cp1 += sizeof(unsigned INT)*4;
- }
- while (l1 >= sizeof(unsigned INT)) {
- if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
- RETURN (false);
- }
- l1 -= sizeof(unsigned INT);
- cp1 += sizeof(unsigned INT);
- }
- if (l1 >= sizeof(unsigned short)) {
- if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
- RETURN (false);
- }
- l1 -= sizeof(unsigned short);
- cp1 += sizeof(unsigned short);
- }
- while (l1) {
- if (*cp1 != *(cp1+addrDelta)) {
- RETURN (false);
- }
- l1--;
- cp1++;
- }
-
- RETURN (true);
+ if ((cls == myCls) || (__isByteArrayLike(self) && __isByteArrayLike(aByteArray))) {
+ l2 = __byteArraySize(aByteArray);
+ l1 = __byteArraySize(self);
+ if (l1 != l2) {
+ RETURN ( false );
+ }
+
+ cp1 = __byteArrayVal(self);
+ cp2 = __byteArrayVal(aByteArray);
+
+ /*
+ * care for instances of subclasses ...
+ */
+ if (cls != ByteArray) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ cp2 += n;
+ cp1 += n;
+ l1 -= n;
+ }
+
+ addrDelta = cp2 - cp1;
+ while (l1 >= (sizeof(unsigned INT) * 4)) {
+ if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
+ RETURN (false);
+ }
+ if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
+ RETURN (false);
+ }
+ if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
+ RETURN (false);
+ }
+ if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
+ RETURN (false);
+ }
+ l1 -= sizeof(unsigned INT)*4;
+ cp1 += sizeof(unsigned INT)*4;
+ }
+ while (l1 >= sizeof(unsigned INT)) {
+ if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
+ RETURN (false);
+ }
+ l1 -= sizeof(unsigned INT);
+ cp1 += sizeof(unsigned INT);
+ }
+ if (l1 >= sizeof(unsigned short)) {
+ if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
+ RETURN (false);
+ }
+ l1 -= sizeof(unsigned short);
+ cp1 += sizeof(unsigned short);
+ }
+ while (l1) {
+ if (*cp1 != *(cp1+addrDelta)) {
+ RETURN (false);
+ }
+ l1--;
+ cp1++;
+ }
+
+ RETURN (true);
}
%}.
^ super = aByteArray
+
+ "Modified: / 18-06-2020 / 11:59:25 / cg"
! !
!ByteArray methodsFor:'converting'!
@@ -1086,6 +1096,14 @@
].
!
+asImmutableCollection
+ "return a write-protected copy of myself"
+
+ ^ self asImmutableByteArray
+
+ "Created: / 15-03-2019 / 13:48:05 / Stefan Vogel"
+!
+
asInteger
"convert myself to an unsigned integer - the first byte is most significant.
This is also in Squeak."
@@ -1231,14 +1249,16 @@
super beImmutable.
self class == ByteArray ifTrue:[
self changeClassTo:ImmutableByteArray.
- ] ifFalse:[
- self shouldNotImplement.
].
+
+ "Modified: / 09-06-2019 / 15:14:59 / Claus Gittinger"
!
beSigned
- "make mayself signed.
- elements > 127 are converted to negative numbers."
+ "destructively make mayself signed.
+ elements > 127 are converted to negative numbers.
+ WARNING: this changes the receiver itself
+ - use this only for initialization of new instances"
self class == ByteArray ifTrue:[
self changeClassTo:SignedByteArray.
@@ -1247,12 +1267,15 @@
].
"
- #[ 1 2 3 128 255] copy beSigned
+ #[ 1 2 3 128 255 ] copy beSigned
+ #[ 1 2 3 128 255 ] beImmutable beSigned
"
+
+ "Modified: / 09-06-2019 / 14:57:56 / Claus Gittinger"
!
beUnsigned
- "that's what I am (but I don't know if this is true for subclasses."
+ "that's what I am (but I don't know if this is true for subclasses)."
self class == ByteArray ifTrue:[
^ self.
@@ -1260,8 +1283,10 @@
self shouldNotImplement.
"
- #[ 1 2 3 128 255] copy beUnsigned
+ #[ 1 2 3 128 255 ] copy beUnsigned
"
+
+ "Modified (comment): / 09-06-2019 / 14:58:22 / Claus Gittinger"
!
decodeAsLiteralArray
@@ -1491,116 +1516,118 @@
if (__isSmallInteger(aNumber)
&& __bothSmallInteger(start, stop)
&& __isBytes(self)) {
- len = __byteArraySize(self);
- index1 = __intVal(start);
- index2 = __intVal(stop);
-
- dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
- if ((cls = __qClass(self)) != @global(ByteArray)) {
- int nInst;
-
- nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- dstp += nInst;
- len -= nInst;
- }
-
- value = __intVal(aNumber);
- if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */
- && (index1 <= index2)
- && (index1 > 0)) {
- if (index2 <= len) {
- count = index2 - index1 + 1;
+ len = __byteArraySize(self);
+ index1 = __intVal(start);
+ index2 = __intVal(stop);
+
+ dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
+ if ((cls = __qClass(self)) != @global(ByteArray)) {
+ int nInst;
+
+ if (cls == ImmutableByteArray) goto fallBack;
+ nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ dstp += nInst;
+ len -= nInst;
+ }
+
+ value = __intVal(aNumber);
+ if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */
+ && (index1 <= index2)
+ && (index1 > 0)) {
+ if (index2 <= len) {
+ count = index2 - index1 + 1;
#ifdef memset4
- if (count > 20) {
- /* fill unaligned part */
- while (((unsigned INT)dstp & 3) != 0) {
- *dstp++ = value;
- count--;
- }
- /* fill aligned part */
- {
- int n4 = count & ~3;
- int v4, nW;
-
- v4 = (value << 8) | value;
- v4 = (v4 << 16) | v4;
- nW = n4>>2;
- memset4(dstp, v4, nW);
- count -= n4;
- dstp += n4;
- }
- while (count--) {
- *dstp++ = value;
- }
- RETURN (self);
- }
+ if (count > 20) {
+ /* fill unaligned part */
+ while (((unsigned INT)dstp & 3) != 0) {
+ *dstp++ = value;
+ count--;
+ }
+ /* fill aligned part */
+ {
+ int n4 = count & ~3;
+ int v4, nW;
+
+ v4 = (value << 8) | value;
+ v4 = (v4 << 16) | v4;
+ nW = n4>>2;
+ memset4(dstp, v4, nW);
+ count -= n4;
+ dstp += n4;
+ }
+ while (count--) {
+ *dstp++ = value;
+ }
+ RETURN (self);
+ }
#endif /* memset4 */
#if (__POINTER_SIZE__ == 8)
- {
- INT v8;
-
- v8 = (value << 8) | value;
- v8 = (v8 << 16) | v8;
- v8 = (v8 << 32) | v8;
-
- /* fill unaligned part */
- while ((count > 0) && (((unsigned INT)dstp & 3) != 0)) {
- *dstp++ = value;
- count--;
- }
-
- if ((count >= 4) && (((unsigned INT)dstp & 7) != 0)) {
- ((unsigned int *)dstp)[0] = v8;
- dstp += 4;
- count -= 4;
- }
-
- /* fill aligned part */
- while (count >= 8) {
- ((unsigned INT *)dstp)[0] = v8;
- dstp += 8;
- count -= 8;
- }
-
- /* fill rest */
- if (count >= 4) {
- ((unsigned int *)dstp)[0] = v8;
- dstp += 4;
- count -= 4;
- }
- if (count >= 2) {
- ((unsigned short *)dstp)[0] = v8;
- dstp += 2;
- count -= 2;
- }
- if (count) {
- *dstp = value;
- }
- RETURN (self);
- }
+ {
+ INT v8;
+
+ v8 = (value << 8) | value;
+ v8 = (v8 << 16) | v8;
+ v8 = (v8 << 32) | v8;
+
+ /* fill unaligned part */
+ while ((count > 0) && (((unsigned INT)dstp & 3) != 0)) {
+ *dstp++ = value;
+ count--;
+ }
+
+ if ((count >= 4) && (((unsigned INT)dstp & 7) != 0)) {
+ ((unsigned int *)dstp)[0] = v8;
+ dstp += 4;
+ count -= 4;
+ }
+
+ /* fill aligned part */
+ while (count >= 8) {
+ ((unsigned INT *)dstp)[0] = v8;
+ dstp += 8;
+ count -= 8;
+ }
+
+ /* fill rest */
+ if (count >= 4) {
+ ((unsigned int *)dstp)[0] = v8;
+ dstp += 4;
+ count -= 4;
+ }
+ if (count >= 2) {
+ ((unsigned short *)dstp)[0] = v8;
+ dstp += 2;
+ count -= 2;
+ }
+ if (count) {
+ *dstp = value;
+ }
+ RETURN (self);
+ }
#endif /* 64bit */
#ifdef FAST_MEMSET
- memset(dstp, value, count);
+ memset(dstp, value, count);
#else
# ifdef __UNROLL_LOOPS__
- while (count >= 8) {
- dstp[0] = dstp[1] = dstp[2] = dstp[3] =
- dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
- dstp += 8;
- count -= 8;
- }
+ while (count >= 8) {
+ dstp[0] = dstp[1] = dstp[2] = dstp[3] =
+ dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
+ dstp += 8;
+ count -= 8;
+ }
# endif /* __UNROLL_LOOPS__ */
- while (count--) {
- *dstp++ = value;
- }
+ while (count--) {
+ *dstp++ = value;
+ }
#endif
- RETURN (self);
- }
- }
+ RETURN (self);
+ }
+ }
}
+fallBack: ;
%}.
"
fall back in case of non-integer index or out-of-bound index/value;
@@ -1613,6 +1640,8 @@
(ByteArray new:20) from:10 to:20 put:1
(ByteArray new:20) from:1 to:10 put:1
"
+
+ "Modified: / 18-06-2020 / 12:02:38 / cg"
! !
!ByteArray methodsFor:'image manipulation support'!
@@ -1636,159 +1665,168 @@
"perform a special case of an aligned bitBlit operation.
Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
of some logical operation, as specified by the ruleSymbol.
- SourceBytes are fetched starting at sourceOffset.
+ SourceBytes /that may also be s String) are fetched starting at sourceOffset.
Valid rule symbols are:
- #copy - trivial; same as replaceBytesFrom:to:with:startingAt:
- #bitXor: - xoring; byte[dI] = byte[dI] bitXor:(srcByte[sI])
- #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:(srcByte[sI])
- #bitOr: - oring; byte[dI] = byte[dI] bitOr:(srcByte[sI])
- #+ - adding; byte[dI] = (byte[dI] + (srcByte[sI])) mod: 256
- #- - subtract; byte[dI] = (byte[dI] - (srcByte[sI])) mod: 256
+ #copy - trivial; same as replaceBytesFrom:to:with:startingAt:
+ #bitXor: - xoring; byte[dI] = byte[dI] bitXor:(srcByte[sI])
+ #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:(srcByte[sI])
+ #bitOr: - oring; byte[dI] = byte[dI] bitOr:(srcByte[sI])
+ #+ - adding; byte[dI] = (byte[dI] + (srcByte[sI])) mod: 256
+ #- - subtract; byte[dI] = (byte[dI] - (srcByte[sI])) mod: 256
Warning: this is a destructive operation - elements in the receiver are overwritten.
"
|srcIdx|
%{
- if ((__isByteArrayLike(sourceBytes))
- && (__qClass(self) == ByteArray)
- && __isSmallInteger(dstStart)
- && __isSmallInteger(dstEnd)
+ if (__qClass(self) == ByteArray
+ && __bothSmallInteger(dstStart, dstEnd)
&& __isSmallInteger(sourceStart)) {
- unsigned char *srcP = __ByteArrayInstPtr(sourceBytes)->ba_element;
- unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
- int srcLen = __byteArraySize(sourceBytes);
- int dstLen = __byteArraySize(self);
- int __srcStart = __intVal(sourceStart);
- int __dstStart = __intVal(dstStart);
- int count = __intVal(dstEnd) - __dstStart + 1;
-
- if ((__dstStart >= 1)
- && (__srcStart >= 1)
- && ((__dstStart + count - 1) <= dstLen)
- && ((__srcStart + count - 1) <= srcLen)) {
- srcP += __srcStart - 1;
- dstP += __dstStart - 1;
+ unsigned char *dstP = __byteArrayVal(self);
+ int dstLen = __byteArraySize(self);
+ int __srcStart = __intVal(sourceStart);
+ int __dstStart = __intVal(dstStart);
+ int count = __intVal(dstEnd) - __dstStart + 1;
+ unsigned char *srcP;
+ int srcLen;
+
+ if (__isByteArrayLike(sourceBytes)) {
+ srcP = __byteArrayVal(sourceBytes);
+ srcLen = __byteArraySize(sourceBytes);
+ } else if (__isStringLike(sourceBytes)) {
+ srcP = _stringVal(sourceBytes);
+ srcLen = __stringSize(sourceBytes);
+ } else
+ goto out;
+
+ if ((__dstStart >= 1)
+ && (__srcStart >= 1)
+ && ((__dstStart + count - 1) <= dstLen)
+ && ((__srcStart + count - 1) <= srcLen)) {
+ srcP += __srcStart - 1;
+ dstP += __dstStart - 1;
#define OP_LOOP_BYTES(OP) \
while (count >= 4) { \
- (dstP[0]) OP (srcP[0]); \
- (dstP[1]) OP (srcP[1]); \
- (dstP[2]) OP (srcP[2]); \
- (dstP[3]) OP (srcP[3]); \
- srcP += 4; \
- dstP += 4; \
- count -= 4; \
+ (dstP[0]) OP (srcP[0]); \
+ (dstP[1]) OP (srcP[1]); \
+ (dstP[2]) OP (srcP[2]); \
+ (dstP[3]) OP (srcP[3]); \
+ srcP += 4; \
+ dstP += 4; \
+ count -= 4; \
} \
while (count > 0) { \
- *dstP OP (*srcP); \
- srcP++; \
- dstP++; \
- count--; \
+ *dstP OP (*srcP); \
+ srcP++; \
+ dstP++; \
+ count--; \
}
#define OP_LOOP(OP) \
while (count >= 16) { \
- ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \
- ((unsigned int *)dstP)[1] OP (((unsigned int *)srcP)[1]); \
- ((unsigned int *)dstP)[2] OP (((unsigned int *)srcP)[2]); \
- ((unsigned int *)dstP)[3] OP (((unsigned int *)srcP)[3]); \
- srcP += 16; \
- dstP += 16; \
- count -= 16; \
+ ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \
+ ((unsigned int *)dstP)[1] OP (((unsigned int *)srcP)[1]); \
+ ((unsigned int *)dstP)[2] OP (((unsigned int *)srcP)[2]); \
+ ((unsigned int *)dstP)[3] OP (((unsigned int *)srcP)[3]); \
+ srcP += 16; \
+ dstP += 16; \
+ count -= 16; \
} \
while (count >= 4) { \
- ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \
- srcP += 4; \
- dstP += 4; \
- count -= 4; \
+ ((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]); \
+ srcP += 4; \
+ dstP += 4; \
+ count -= 4; \
} \
while (count > 0) { \
- *dstP OP (*srcP); \
- srcP++; \
- dstP++; \
- count--; \
+ *dstP OP (*srcP); \
+ srcP++; \
+ dstP++; \
+ count--; \
}
- if (ruleSymbol == @symbol(bitXor:)) {
- OP_LOOP( ^= )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitXorNot:)) {
- OP_LOOP( ^=~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitAnd:)) {
- OP_LOOP( &= )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitAndNot:)) {
- OP_LOOP( &=~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitOr:)) {
- OP_LOOP( |= )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitOrNot:)) {
- OP_LOOP( |=~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(copy)) {
- OP_LOOP( = )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(copyNot)) {
- OP_LOOP( =~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(+)) {
- OP_LOOP_BYTES( += )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(-)) {
- OP_LOOP_BYTES( -= )
- RETURN (self);
- }
- }
+ if (ruleSymbol == @symbol(bitXor:)) {
+ OP_LOOP( ^= )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitXorNot:)) {
+ OP_LOOP( ^=~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitAnd:)) {
+ OP_LOOP( &= )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitAndNot:)) {
+ OP_LOOP( &=~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitOr:)) {
+ OP_LOOP( |= )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitOrNot:)) {
+ OP_LOOP( |=~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(copy)) {
+ OP_LOOP( = )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(copyNot)) {
+ OP_LOOP( =~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(+)) {
+ OP_LOOP_BYTES( += )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(-)) {
+ OP_LOOP_BYTES( -= )
+ RETURN (self);
+ }
+ }
}
#undef OP_LOOP_BYTES
#undef OP_LOOP
-
+out:;
%}.
ruleSymbol == #copy ifTrue:[
- self replaceFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart.
- ^ self
+ self replaceFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart.
+ ^ self
].
srcIdx := sourceStart.
dstStart to:dstEnd do:[:dstIdx |
- self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:(sourceBytes at:srcIdx)).
- srcIdx := srcIdx + 1.
+ self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:(sourceBytes at:srcIdx)).
+ srcIdx := srcIdx + 1.
].
"
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
+ bitBlitBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
+ bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#bitAnd:
+ bitBlitBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#bitAnd:
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
+ bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
#[255 0 0 0 0 0 0 0]
- bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
+ bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#+
+ bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#+
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#+
+ bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#+
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#copyNot
+ bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#copyNot
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 with:(1 to:8) startingAt:1 rule:#+
+ bitBlitBytesFrom:1 to:8 with:(1 to:8) startingAt:1 rule:#+
"
+
+ "Modified: / 29-01-2020 / 14:11:05 / Stefan Vogel"
!
bitBlitBytesFrom:dstStart to:dstEnd withConstant:sourceByte rule:ruleSymbol
@@ -1796,149 +1834,148 @@
Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
of some logical operation, as specified by the ruleSymbol.
Valid rule symbols are:
- #copy - trivial; same as from:to:put:
- #bitXor: - xoring; byte[dI] = byte[dI] bitXor:sourceConst
- #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:sourceConst
- #bitOr: - oring; byte[dI] = byte[dI] bitOr:sourceConst
- #+ - adding; byte[dI] = (byte[dI] + sourceConst) mod: 256
- #- - subtract; byte[dI] = (byte[dI] - sourceConst) mod: 256
+ #copy - trivial; same as from:to:put:
+ #bitXor: - xoring; byte[dI] = byte[dI] bitXor:sourceConst
+ #bitAnd: - anding; byte[dI] = byte[dI] bitAnd:sourceConst
+ #bitOr: - oring; byte[dI] = byte[dI] bitOr:sourceConst
+ #+ - adding; byte[dI] = (byte[dI] + sourceConst) mod: 256
+ #- - subtract; byte[dI] = (byte[dI] - sourceConst) mod: 256
Warning: this is a destructive operation - elements in the receiver are overwritten.
"
- |srcIdx|
-
%{
if ((__qClass(self) == ByteArray)
- && __isSmallInteger(dstStart)
- && __isSmallInteger(dstEnd)
+ && __bothSmallInteger(dstStart, dstEnd)
&& __isSmallInteger(sourceByte)) {
- unsigned char srcByte = __intVal(sourceByte);
- unsigned srcWord;
- unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
- int dstLen = __byteArraySize(self);
- int __dstStart = __intVal(dstStart);
- int count = __intVal(dstEnd) - __dstStart + 1;
-
- srcWord = (srcByte << 8) | srcByte;
- srcWord = (srcWord << 16) | srcWord;
- if ((__dstStart >= 1)
- && ((__dstStart + count - 1) <= dstLen)) {
- dstP += __dstStart - 1;
+ unsigned char srcByte = __intVal(sourceByte);
+ unsigned srcWord;
+ unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
+ int dstLen = __byteArraySize(self);
+ int __dstStart = __intVal(dstStart);
+ int count = __intVal(dstEnd) - __dstStart + 1;
+
+ srcWord = (srcByte << 8) | srcByte;
+ srcWord = (srcWord << 16) | srcWord;
+ if ((__dstStart >= 1)
+ && ((__dstStart + count - 1) <= dstLen)) {
+ dstP += __dstStart - 1;
#define OP_LOOP_BYTES(OP) \
while (count >= 4) { \
- dstP[0] OP srcByte; \
- dstP[1] OP srcByte; \
- dstP[2] OP srcByte; \
- dstP[3] OP srcByte; \
- dstP += 4; \
- count -= 4; \
+ dstP[0] OP srcByte; \
+ dstP[1] OP srcByte; \
+ dstP[2] OP srcByte; \
+ dstP[3] OP srcByte; \
+ dstP += 4; \
+ count -= 4; \
} \
while (count > 0) { \
- *dstP OP srcByte; \
- dstP++; \
- count--; \
+ *dstP OP srcByte; \
+ dstP++; \
+ count--; \
}
#define OP_LOOP_INT32(OP) \
while (count >= 16) { \
- ((unsigned int *)dstP)[0] OP srcWord; \
- ((unsigned int *)dstP)[1] OP srcWord; \
- ((unsigned int *)dstP)[2] OP srcWord; \
- ((unsigned int *)dstP)[3] OP srcWord; \
- dstP += 16; \
- count -= 16; \
+ ((unsigned int *)dstP)[0] OP srcWord; \
+ ((unsigned int *)dstP)[1] OP srcWord; \
+ ((unsigned int *)dstP)[2] OP srcWord; \
+ ((unsigned int *)dstP)[3] OP srcWord; \
+ dstP += 16; \
+ count -= 16; \
} \
#define OP_LOOP(OP) \
OP_LOOP_INT32(OP) \
while (count >= 4) { \
- ((unsigned int *)dstP)[0] OP srcWord; \
- dstP += 4; \
- count -= 4; \
+ ((unsigned int *)dstP)[0] OP srcWord; \
+ dstP += 4; \
+ count -= 4; \
} \
while (count > 0) { \
- *dstP OP srcByte; \
- dstP++; \
- count--; \
+ *dstP OP srcByte; \
+ dstP++; \
+ count--; \
}
- if (ruleSymbol == @symbol(bitXor:)) {
- OP_LOOP( ^= )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitXorNot:)) {
- OP_LOOP( ^=~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitAnd:)) {
- OP_LOOP( &= )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitAndNot:)) {
- OP_LOOP( &=~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitOr:)) {
- OP_LOOP( |= )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(bitOrNot:)) {
- OP_LOOP( |=~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(copy)) {
- OP_LOOP( = )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(copyNot)) {
- OP_LOOP( =~ )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(+)) {
- OP_LOOP_BYTES( += )
- RETURN (self);
- }
- if (ruleSymbol == @symbol(-)) {
- OP_LOOP_BYTES( -= )
- RETURN (self);
- }
- }
+ if (ruleSymbol == @symbol(bitXor:)) {
+ OP_LOOP( ^= )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitXorNot:)) {
+ OP_LOOP( ^=~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitAnd:)) {
+ OP_LOOP( &= )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitAndNot:)) {
+ OP_LOOP( &=~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitOr:)) {
+ OP_LOOP( |= )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(bitOrNot:)) {
+ OP_LOOP( |=~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(copy)) {
+ OP_LOOP( = )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(copyNot)) {
+ OP_LOOP( =~ )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(+)) {
+ OP_LOOP_BYTES( += )
+ RETURN (self);
+ }
+ if (ruleSymbol == @symbol(-)) {
+ OP_LOOP_BYTES( -= )
+ RETURN (self);
+ }
+ }
}
#undef OP_LOOP_BYTES
#undef OP_LOOP
%}.
ruleSymbol == #copy ifTrue:[
- self from:dstStart to:dstEnd put:sourceByte.
- ^ self
+ self from:dstStart to:dstEnd put:sourceByte.
+ ^ self
].
dstStart to:dstEnd do:[:dstIdx |
- self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:sourceByte).
+ self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:sourceByte).
].
"
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:3 withConstant:1 rule:#bitXor:
+ bitBlitBytesFrom:1 to:3 withConstant:1 rule:#bitXor:
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitXor:
+ bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitXor:
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitAnd:
+ bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitAnd:
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
+ bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
#[255 0 0 0 0 0 0 0]
- bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
+ bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:4 withConstant:1 rule:#+
+ bitBlitBytesFrom:1 to:4 withConstant:1 rule:#+
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:4 withConstant:1 rule:#-
+ bitBlitBytesFrom:1 to:4 withConstant:1 rule:#-
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:4 withConstant:1 rule:#copyNot
+ bitBlitBytesFrom:1 to:4 withConstant:1 rule:#copyNot
#[1 2 3 4 5 6 7 8]
- bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
+ bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
"
+
+ "Modified (format): / 29-01-2020 / 14:12:06 / Stefan Vogel"
!
bitOrBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
@@ -2311,8 +2348,9 @@
!
invert
- "invert all bytes - used with image manipulations
+ "invert all bytes inplace - used with image manipulations
written as a primitive for speed.
+ Warning: destructive; modifies the receiver - not a copy.
Q: is this really needed ?"
%{ /* NOCONTEXT */
@@ -2321,30 +2359,30 @@
REGISTER int cnt;
if (__qClass(self) == @global(ByteArray)) {
- cnt = __byteArraySize(self);
- dst = __ByteArrayInstPtr(self)->ba_element;
- if (((INT)dst & (sizeof(long)-1)) == 0) { // aligned
- ldst = (unsigned long *)dst;
- while (cnt >= (sizeof(long))*4) {
- ldst[0] = ~(ldst[0]);
- ldst[1] = ~(ldst[1]);
- ldst[2] = ~(ldst[2]);
- ldst[3] = ~(ldst[3]);
- ldst += 4;
- cnt -= (sizeof(long))*4;
- }
- while (cnt >= sizeof(long)) {
- *ldst = ~(*ldst);
- ldst++;
- cnt -= sizeof(long);
- }
- dst = (unsigned char *)ldst;
- }
- while (cnt--) {
- *dst = ~(*dst);
- dst++;
- }
- RETURN ( self );
+ cnt = __byteArraySize(self);
+ dst = __ByteArrayInstPtr(self)->ba_element;
+ if (((INT)dst & (sizeof(long)-1)) == 0) { // aligned
+ ldst = (unsigned long *)dst;
+ while (cnt >= (sizeof(long))*4) {
+ ldst[0] = ~(ldst[0]);
+ ldst[1] = ~(ldst[1]);
+ ldst[2] = ~(ldst[2]);
+ ldst[3] = ~(ldst[3]);
+ ldst += 4;
+ cnt -= (sizeof(long))*4;
+ }
+ while (cnt >= sizeof(long)) {
+ *ldst = ~(*ldst);
+ ldst++;
+ cnt -= sizeof(long);
+ }
+ dst = (unsigned char *)ldst;
+ }
+ while (cnt--) {
+ *dst = ~(*dst);
+ dst++;
+ }
+ RETURN ( self );
}
%}.
self bitBlitBytesFrom:1 to:self size withConstant:16rFF rule:#bitXor:
@@ -2352,14 +2390,16 @@
"
#[1 2 3 4 5 6 7 8 9 10] copy invert
#[1 2 3 4 5 6 7 8 9 10] copy
- bitBlitBytesFrom:1 to:10 withConstant:16rFF rule:#bitXor:
+ bitBlitBytesFrom:1 to:10 withConstant:16rFF rule:#bitXor:
|l|
l := ByteArray fromHexString:'0102030405060708090a0b0c0d0e0f1112131415161718191a1b1c1d1e1f'.
Time millisecondsToRun:[
- 1000000 timesRepeat:[ l invert ].
+ 1000000 timesRepeat:[ l invert ].
]
"
+
+ "Modified (comment): / 03-06-2019 / 18:08:47 / Claus Gittinger"
!
reverse
@@ -2473,17 +2513,22 @@
^ super reverse
"
- #[1 2 3 4 5] reverse
- #[1 2 3 4] reverse
- #[1 2 3 4 5] reverse
- #[1 2 3 4 5 6] reverse
- #[1 2 3 4 5 6 7] reverse
- #[1 2 3 4 5 6 7 8] reverse
- #[1 2 3 4 5 6 7 8 9] reverse
- #[1 2 3 4 5 6 7 8 9 10] reverse
- #[1 2 3 4 5 6 7 8 9 10 11 12] reverse
- #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] reverse
- #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] reverse
+ #[1 2 3 4 5] copy reverse
+ #[] copy reverse
+ #[1] copy reverse
+ #[1 2] copy reverse
+ #[1 2 3] copy reverse
+ #[1 2 3 4] copy reverse
+ #[1 2 3 4 5] copy reverse
+ #[1 2 3 4 5 6] copy reverse
+ #[1 2 3 4 5 6 7] copy reverse
+ #[1 2 3 4 5 6 7 8] copy reverse
+ #[1 2 3 4 5 6 7 8] copy reverseFrom:2 to:5
+ #[1 2 3 4 5 6 7 8 9] copy reverse
+ #[1 2 3 4 5 6 7 8 9 10] copy reverse
+ #[1 2 3 4 5 6 7 8 9 10 11 12] copy reverse
+ #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] copy reverse
+ #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] copy reverse
(1 to:255) asByteArray reverse
1 to:1024 do:[:i|
@@ -2515,6 +2560,39 @@
]
]
"
+
+ "Modified (comment): / 01-05-2017 / 12:56:13 / cg"
+!
+
+swap:i1 with:i2
+ "spap the bytes at i1 and i2"
+
+%{ /* NOCONTEXT */
+
+ REGISTER unsigned char *p;
+ unsigned int __i1, __i2;
+ int sz;
+ unsigned int t;
+
+ if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) {
+ __i1 = __intVal(i1) - 1;
+ __i2 = __intVal(i2) - 1;
+ sz = __byteArraySize(self);
+ p = __ByteArrayInstPtr(self)->ba_element;
+ if ((__i1 < sz) && (__i2 < sz)) {
+ t = p[__i1];
+ p[__i1] = p[__i2];
+ p[__i2] = t;
+ RETURN ( self );
+ }
+ }
+%}.
+ ^ super swap:i1 with:i2
+
+ "
+ #[1 2 3 4 5 6 7 8 9 10] copy swapIndex:1 and:10
+ #[1 2 3 4 5 6 7 8 9 10 11] copy swapIndex:5 and:6
+ "
!
swapBytes
@@ -2567,37 +2645,6 @@
"
!
-swapIndex:i1 and:i2
- "spap the bytes with i1 and i2"
-
-%{ /* NOCONTEXT */
-
- REGISTER unsigned char *p;
- unsigned int __i1, __i2;
- int sz;
- unsigned int t;
-
- if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) {
- __i1 = __intVal(i1) - 1;
- __i2 = __intVal(i2) - 1;
- sz = __byteArraySize(self);
- p = __ByteArrayInstPtr(self)->ba_element;
- if (__i1 < sz && __i2 < sz) {
- t = p[__i1];
- p[__i1] = p[__i2];
- p[__i2] = t;
- }
- RETURN ( self );
- }
-%}.
- ^ super swapIndex:i1 and:i2 "/ rubbish - there is no one currently
-
- "
- #[1 2 3 4 5 6 7 8 9 10] copy swapIndex:1 and:10
- #[1 2 3 4 5 6 7 8 9 10 11] copy swapIndex:5 and:6
- "
-!
-
swapLongs
"swap long bytes inplace
- any partial longs at the end are not swapped."
@@ -2687,25 +2734,25 @@
"
! !
-
!ByteArray methodsFor:'printing & storing'!
displayOn:aGCOrStream
"return a printed representation of the receiver for displaying"
+ |cls|
+
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
- "/ ST/X (and some old ST80's) mean: draw-yourself on a GC.
- |cls|
-
+ "/ old ST80 means: draw-yourself on a GC.
cls := self class.
((cls == ByteArray or:[cls == ImmutableByteArray]) and:[aGCOrStream isStream]) ifTrue:[
- self storeOn:aGCOrStream.
- ^ self
+ self storeOn:aGCOrStream.
+ ^ self
].
^ super displayOn:aGCOrStream
- "Created: 25.10.1995 / 13:33:26 / cg"
- "Modified: 22.4.1996 / 12:54:06 / cg"
+ "Created: / 25-10-1995 / 13:33:26 / cg"
+ "Modified: / 22-04-1996 / 12:54:06 / cg"
+ "Modified (comment): / 22-02-2017 / 16:54:27 / cg"
!
printOn:aStream
@@ -2758,21 +2805,48 @@
printOn:aStream base:radix showRadix:showRadix
"append a printed representation to aStream in the given number base."
- |cls|
+ self printOn:aStream base:radix showRadix:showRadix wrapAfter:nil
+
+ "
+ #[1 2 3 4 5] printOn:Transcript base:2
+ 'Hello World' asByteArray printOn:Transcript base:2 showRadix:false
+
+ #[1 2 3 4 5] storeString
+ #[1 2 3 4 5] displayString
+ #[1 2 3 4 5] printString
+ "
+
+ "Modified: / 12.9.1997 / 22:11:33 / cg"
+ "Modified: / 17.3.1999 / 17:01:31 / stefan"
+ "Created: / 31.10.2001 / 09:43:41 / cg"
+!
+
+printOn:aStream base:radix showRadix:showRadix wrapAfter:colCntOrNil
+ "append a printed representation to aStream in the given number base."
+
+ |cls count|
((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
- "/ care for subclasses
- aStream nextPutAll:'#['.
- self
- do:[:byte | byte printOn:aStream base:radix showRadix:showRadix]
- separatedBy:[aStream space].
- aStream nextPut:$].
- ^ self
+ "/ care for subclasses
+ aStream nextPutAll:'#['.
+ count := 0.
+ self
+ do:[:byte |
+ byte printOn:aStream base:radix showRadix:showRadix.
+ colCntOrNil notNil ifTrue:[
+ count := count + 1.
+ count == colCntOrNil ifTrue:[ aStream cr. count := 0 ].
+ ]
+ ]
+ separatedBy:[aStream space].
+ aStream nextPut:$].
+ ^ self
].
^ self printOn:aStream
"
#[1 2 3 4 5] printOn:Transcript base:2
+ (1 to:255) asByteArray printOn:Transcript base:16 showRadix:false wrapAfter:16
'Hello World' printOn:Transcript base:2
#[1 2 3 4 5] storeString
@@ -2831,14 +2905,15 @@
|cls|
- ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
- "/ care for subclasses
- aStream nextPutAll:'#['.
- self
- do:[:byte | byte storeOn:aStream]
- separatedBy:[aStream space].
- aStream nextPutAll:']'.
- ^ self
+ cls := self class.
+ (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
+ "/ care for subclasses
+ aStream nextPutAll:'#['.
+ self
+ do:[:byte | byte storeOn:aStream]
+ separatedBy:[aStream space].
+ aStream nextPut:$].
+ ^ self
].
^ super storeOn:aStream
@@ -2850,11 +2925,19 @@
#[1 2 3 4 5] printString
"
- "Modified: 12.9.1997 / 22:11:33 / cg"
+ "Modified: / 12-09-1997 / 22:11:33 / cg"
+ "Modified: / 17-02-2017 / 10:50:37 / stefan"
! !
!ByteArray methodsFor:'queries'!
+characterSize
+ "answer the size in bits of my largest character (actually only 7, 8, 16 or 32).
+ Needed in case someone writes bytes to a CharacterWriteStream (comanche response)"
+
+ ^ 8
+!
+
containsNon7BitAscii
"return true, if any byte in the receiver has the 7th bit on.
This my look as a too specific operation to be put here,
@@ -2902,9 +2985,28 @@
^ false.
!
+isEmpty
+ "return true if the receiver is empty (i.e. if size == 0)
+ Redefined here for performance"
+
+%{ /* NOCONTEXT */
+#ifndef __SCHTEAM__
+ if (__isByteArrayLike(self)) {
+ RETURN ( (__byteArraySize(self) == 0) ? true : false);
+ }
+#endif /* ! __SCHTEAM__ */
+%}.
+ ^ self size == 0
+
+ "Created: / 16-02-2017 / 15:02:03 / stefan"
+!
+
isValidElement:anObject
"return true, if I can hold this kind of object"
+ "/ notice the self class minVal/maxVal here:
+ "/ I am redefined to logically hold longer objects (shortInts, ints, longInts, etc.)
+
^ anObject isInteger
and:[ (anObject >= self class minVal)
and:[ (anObject <= self class maxVal) ]]
@@ -2950,6 +3052,22 @@
"
!
+notEmpty
+ "return true if the receiver is not empty (i.e. if size ~~ 0)
+ Redefined here for performance"
+
+%{ /* NOCONTEXT */
+#ifndef __SCHTEAM__
+ if (__isByteArrayLike(self)) {
+ RETURN ( (__byteArraySize(self) != 0) ? true : false);
+ }
+#endif /* ! __SCHTEAM__ */
+%}.
+ ^ self size ~~ 0
+
+ "Created: / 16-02-2017 / 15:02:36 / stefan"
+!
+
startsWith:aByteOrByteArray
"return true, if the receiver starts with something, aStringOrChar.
If the argument is empty, true is returned.
@@ -3249,6 +3367,15 @@
!
+isIntegerArray
+ "return true if the receiver has integer elements.
+ These are Byte- and Integer arrays; both signed and unsigned"
+
+ ^ true
+
+ "Created: / 02-03-2019 / 23:11:00 / Claus Gittinger"
+!
+
isLiteral
"return true, if the receiver can be used as a literal constant in ST syntax
(i.e. can be used in constant arrays)"
@@ -3262,7 +3389,6 @@
"Modified: 22.4.1996 / 12:55:30 / cg"
! !
-
!ByteArray class methodsFor:'documentation'!
version