ByteArray.st
branchjv
changeset 17735 6a5bc05f696a
parent 17734 406b1590afe8
child 17742 3fef0ed4c2d5
--- a/ByteArray.st	Thu Nov 05 14:41:30 2009 +0000
+++ b/ByteArray.st	Wed Dec 02 21:30:55 2009 +0000
@@ -1036,6 +1036,13 @@
     "
 !
 
+asImmutableByteArray
+    "return a write-protected copy of myself"
+
+    self assert:(ImmutableByteArray notNil).
+    ^ self copy changeClassTo:ImmutableByteArray
+!
+
 asInteger
     "convert myself to an integer - the first byte is most significant.
      This is also in Squeak."
@@ -1073,44 +1080,44 @@
     stop := self size.
 
     stop > 100 ifTrue:[
-	"/ cg:
-	"/ initial lineBreak
-	outStream cr.
+        "/ cg:
+        "/ initial lineBreak
+        outStream cr.
     ].
     cpl := 0.
 
     [index <= stop] whileTrue:[
-	"take 3 source bytes"
-	n := (self at:index) bitShift:16.
-	(index < stop) ifTrue:[
-	    nextIndex := index + 1.
-	    n := n bitOr:((self at:nextIndex) bitShift:8).
-	    (nextIndex < stop) ifTrue:[
-		n := n bitOr:(self at:(index + 2)).
-	    ].
-	].
-
-	"took me a while to find that one out ..."
-	n := n bitXor:16r820820.
-
-	outStream nextPut:(Character value:(n bitShift:-18) + 32).
-	outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
-	outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
-	outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
-	index := index + 3.
-
-	"/ cg:
-	"/ lineBreak after every 120 characters
-	"/ fromPackedString will ignore those
-	cpl := cpl + 4.
-	cpl >= 120 ifTrue:[
-	    outStream cr.
-	    cpl := 0.
-	].
+        "take 3 source bytes"
+        n := (self at:index) bitShift:16.
+        (index < stop) ifTrue:[
+            nextIndex := index + 1.
+            n := n bitOr:((self at:nextIndex) bitShift:8).
+            (nextIndex < stop) ifTrue:[
+                n := n bitOr:(self at:(index + 2)).
+            ].
+        ].
+        index := index + 3.
+
+        "took me a while to find that one out ..."
+        n := n bitXor:16r820820.
+
+        outStream nextPut:(Character value:((n bitShift:-18) bitAnd:16r3F) + 32).
+        outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
+        outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
+        outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
+
+        "/ cg:
+        "/ lineBreak after every 120 characters
+        "/ fromPackedString will ignore those
+        cpl := cpl + 4.
+        cpl >= 120 ifTrue:[
+            outStream cr.
+            cpl := 0.
+        ].
     ].
     (mod := stop \\ 3) ~~ 0 ifTrue:[
-	outStream backStep.
-	outStream nextPut:(Character value:(mod + 96)).
+        outStream backStep.
+        outStream nextPut:(Character value:(mod + 96)).
     ].
     ^ outStream contents
 
@@ -1146,7 +1153,9 @@
     "encode myself as an array literal, from which a copy of the receiver
      can be reconstructed with #decodeAsLiteralArray."
 
-    self class == ByteArray ifTrue:[
+    |cls|
+
+    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
         ^ self
     ].
     ^ super literalArrayEncoding
@@ -1180,81 +1189,81 @@
     int len, index1, index2, sz;
     OBJ newByteArray;
 
-    if (__isByteArray(self)
+    if (__isByteArrayLike(self)
      && __bothSmallInteger(start, stop)) {
-	len = __byteArraySize(self);
-	index1 = __intVal(start);
-	index2 = __intVal(stop);
-
-	if ((index1 <= index2) && (index1 > 0)) {
-	    if (index2 <= len) {
-		count = index2 - index1 + 1;
-		__PROTECT_CONTEXT__
-		sz = OHDR_SIZE + count;
-		__qNew(newByteArray, sz);       /* OBJECT ALLOCATION */
-		__UNPROTECT_CONTEXT__
-		if (newByteArray != nil) {
-		    __InstPtr(newByteArray)->o_class = ByteArray;
-		    __qSTORE(newByteArray, ByteArray);
-		    dstp = __ByteArrayInstPtr(newByteArray)->ba_element;
-		    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
+        len = __byteArraySize(self);
+        index1 = __intVal(start);
+        index2 = __intVal(stop);
+
+        if ((index1 <= index2) && (index1 > 0)) {
+            if (index2 <= len) {
+                count = index2 - index1 + 1;
+                __PROTECT_CONTEXT__
+                sz = OHDR_SIZE + count;
+                __qNew(newByteArray, sz);       /* OBJECT ALLOCATION */
+                __UNPROTECT_CONTEXT__
+                if (newByteArray != nil) {
+                    __InstPtr(newByteArray)->o_class = ByteArray;
+                    __qSTORE(newByteArray, ByteArray);
+                    dstp = __ByteArrayInstPtr(newByteArray)->ba_element;
+                    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
 
 #ifdef bcopy4
-		    if (((unsigned INT)srcp & 3) == ((unsigned INT)dstp & 3)) {
-			int nW;
-
-			/* copy unaligned part */
-			while (count && (((unsigned INT)srcp & 3) != 0)) {
-			    *dstp++ = *srcp++;
-			    count--;
-			}
-			if (count) {
-			    /* copy aligned part */
-			    nW = count >> 2;
-			    if (count & 3) {
-				nW++;
-			    }
-			    bcopy4(srcp, dstp, nW);
-			}
-			RETURN ( newByteArray );
-		    }
+                    if (((unsigned INT)srcp & 3) == ((unsigned INT)dstp & 3)) {
+                        int nW;
+
+                        /* copy unaligned part */
+                        while (count && (((unsigned INT)srcp & 3) != 0)) {
+                            *dstp++ = *srcp++;
+                            count--;
+                        }
+                        if (count) {
+                            /* copy aligned part */
+                            nW = count >> 2;
+                            if (count & 3) {
+                                nW++;
+                            }
+                            bcopy4(srcp, dstp, nW);
+                        }
+                        RETURN ( newByteArray );
+                    }
 #endif /* bcopy4 */
 #if __POINTER_SIZE__ == 8
-		    if (((unsigned INT)srcp & 7) == ((unsigned INT)dstp & 7)) {
-			int nW;
-
-			/* copy unaligned part */
-			while (count && (((unsigned INT)srcp & 7) != 0)) {
-			    *dstp++ = *srcp++;
-			    count--;
-			}
-			/* copy aligned part */
-			while (count >= 8) {
-			    ((unsigned INT *)dstp)[0] = ((unsigned INT *)srcp)[0];
-			    dstp += 8;
-			    srcp += 8;
-			    count -= 8;
-			}
-			/* copy remaining part */
-			while (count) {
-			    *dstp++ = *srcp++;
-			    count--;
-			}
-			RETURN ( newByteArray );
-		    }
+                    if (((unsigned INT)srcp & 7) == ((unsigned INT)dstp & 7)) {
+                        int nW;
+
+                        /* copy unaligned part */
+                        while (count && (((unsigned INT)srcp & 7) != 0)) {
+                            *dstp++ = *srcp++;
+                            count--;
+                        }
+                        /* copy aligned part */
+                        while (count >= 8) {
+                            ((unsigned INT *)dstp)[0] = ((unsigned INT *)srcp)[0];
+                            dstp += 8;
+                            srcp += 8;
+                            count -= 8;
+                        }
+                        /* copy remaining part */
+                        while (count) {
+                            *dstp++ = *srcp++;
+                            count--;
+                        }
+                        RETURN ( newByteArray );
+                    }
 #endif /* bcopy4 */
 
 #ifdef FAST_MEMCPY
-		    bcopy(srcp, dstp, count);
+                    bcopy(srcp, dstp, count);
 #else
-		    while (count--) {
-			*dstp++ = *srcp++;
-		    }
+                    while (count--) {
+                        *dstp++ = *srcp++;
+                    }
 #endif
-		    RETURN ( newByteArray );
-		}
-	    }
-	}
+                    RETURN ( newByteArray );
+                }
+            }
+        }
     }
 %}.
     "
@@ -1297,34 +1306,34 @@
     int len, index1, index2;
     unsigned char scratchBuffer[1024], savec;
 
-    if (__isByteArray(self) && __bothSmallInteger(start, stop)) {
-	len = __byteArraySize(self);
-	index1 = __intVal(start);
-	index2 = __intVal(stop);
-
-	if ((index1 <= index2) && (index1 > 0) && (index2 <= len)) {
-	    count = index2 - index1 + 1;
-	    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
-	    if (index2 < len) {
-		/* temporarily stuff in a '\0' */
-		endp = srcp + count + 1;
-		savec = *endp;
-		*endp = '\0';
-		sym = __MKSYMBOL(srcp, 0);
-		/* must refetch endp (in case of a GC */
-		endp = __ByteArrayInstPtr(self)->ba_element + index1 + count;
-		*endp = savec;
-	    } else {
-		/* not enough space for '\0', copy the bytes */
-		if (count < sizeof(scratchBuffer)) {
-		    bcopy(srcp, scratchBuffer, count);
-		    scratchBuffer[count] = '\0';
-		    sym = __MKSYMBOL(scratchBuffer, 0);
-		}
-	    }
-	}
-	if (sym != nil)
-	    RETURN(sym);
+    if (__isByteArrayLike(self) && __bothSmallInteger(start, stop)) {
+        len = __byteArraySize(self);
+        index1 = __intVal(start);
+        index2 = __intVal(stop);
+
+        if ((index1 <= index2) && (index1 > 0) && (index2 <= len)) {
+            count = index2 - index1 + 1;
+            srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
+            if (index2 < len) {
+                /* temporarily stuff in a '\0' */
+                endp = srcp + count + 1;
+                savec = *endp;
+                *endp = '\0';
+                sym = __MKSYMBOL(srcp, 0);
+                /* must refetch endp (in case of a GC */
+                endp = __ByteArrayInstPtr(self)->ba_element + index1 + count;
+                *endp = savec;
+            } else {
+                /* not enough space for '\0', copy the bytes */
+                if (count < sizeof(scratchBuffer)) {
+                    bcopy(srcp, scratchBuffer, count);
+                    scratchBuffer[count] = '\0';
+                    sym = __MKSYMBOL(scratchBuffer, 0);
+                }
+            }
+        }
+        if (sym != nil)
+            RETURN(sym);
     }
 %}.
     "
@@ -1757,147 +1766,147 @@
      of some logical operation, as specified by the ruleSymbol.
      SourceBytes 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 ((__isByteArray(sourceBytes))
+    if ((__isByteArrayLike(sourceBytes))
      && (__qClass(self) == ByteArray)
      && __isSmallInteger(dstStart)
      && __isSmallInteger(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 *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;
 
 #define OP_LOOP_BYTES(OP) \
     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
 
 %}.
     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:#+
     "
 !
 
@@ -2870,13 +2879,16 @@
 printOn:aStream
     "append a printed representation to aStream"
 
-    self class == ByteArray ifTrue:[    "/ care for subclasses
-	aStream nextPutAll:'#['.
-	self
-	    do:[:byte | byte printOn:aStream]
-	    separatedBy:[aStream space].
-	aStream nextPut:$].
-	^ self
+    |cls|
+
+    "/ care for subclasses
+    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[    
+        aStream nextPutAll:'#['.
+        self
+            do:[:byte | byte printOn:aStream]
+            separatedBy:[aStream space].
+        aStream nextPut:$].
+        ^ self
     ].
     ^ super printOn:aStream
 
@@ -2914,13 +2926,16 @@
 printOn:aStream base:radix showRadix:showRadix
     "append a printed representation to aStream in the given number base."
 
-    self class == ByteArray ifTrue:[    "/ care for subclasses
-	aStream nextPutAll:'#['.
-	self
-	    do:[:byte | byte printOn:aStream base:radix showRadix:showRadix]
-	    separatedBy:[aStream space].
-	aStream nextPut:$].
-	^ self
+    |cls|
+
+    ((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
     ].
     ^ self printOn:aStream
 
@@ -2941,13 +2956,16 @@
 storeArrayElementOn:aStream
     "Store as element of an array. Omit the leading '#'"
 
-    self class == ByteArray ifTrue:[    "/ care for subclasses
-	aStream nextPut:$[.
-	self
-	    do:[:byte | byte storeOn:aStream]
-	    separatedBy:[aStream space].
-	aStream nextPut:$].
-	^ self
+    |cls|
+
+    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[    
+        "/ care for subclasses
+        aStream nextPut:$[.
+        self
+            do:[:byte | byte storeOn:aStream]
+            separatedBy:[aStream space].
+        aStream nextPut:$].
+        ^ self
     ].
     super storeArrayElementOn:aStream
 
@@ -2967,13 +2985,16 @@
     "append a printed representation from which the receiver can be
      reconstructed to aStream. (reimplemented to make it look better)"
 
-    self class == ByteArray ifTrue:[    "/ care for subclasses
-	aStream nextPutAll:'#['.
-	self
-	    do:[:byte | byte storeOn:aStream]
-	    separatedBy:[aStream space].
-	aStream nextPutAll:']'.
-	^ self
+    |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
     ].
     ^ super storeOn:aStream
 
@@ -3161,7 +3182,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'searching'!
 
 indexOf:aByte startingAt:start
@@ -3244,11 +3264,12 @@
 !ByteArray class methodsFor:'documentation'!
 
 version
-    ^ '$Id: ByteArray.st 10477 2009-11-05 14:41:30Z vranyj1 $'
+    ^ '$Id: ByteArray.st 10480 2009-12-02 21:30:55Z vranyj1 $'
 !
 
 version_CVS
-    ^ '$Id: ByteArray.st 10477 2009-11-05 14:41:30Z vranyj1 $'
+    ^ '§Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.197 2009/11/17 13:29:37 cg Exp §'
 ! !
 
 
+