ByteArray.st
branchjv
changeset 17754 5322906cdb6a
parent 17751 b2273fa8d59f
child 17761 b0e5971141bc
--- a/ByteArray.st	Thu Feb 25 22:58:21 2010 +0000
+++ b/ByteArray.st	Mon Mar 08 21:39:02 2010 +0000
@@ -173,7 +173,6 @@
     "Modified: 23.4.1996 / 15:56:25 / cg"
 ! !
 
-
 !ByteArray methodsFor:'Compatibility-Squeak'!
 
 bitXor:aByteArray
@@ -187,12 +186,6 @@
         answer at: each put: ((self at: each) bitXor: (aByteArray at: each))
     ].
     ^ answer
-!
-
-copyFromByteArray:aByteArray
-    "copy as much as possible from aByteArray"
-
-    self replaceFrom:1 to:(self size min:aByteArray size) with:aByteArray startingAt:1
 ! !
 
 !ByteArray methodsFor:'Compatibility-VW'!
@@ -664,39 +657,38 @@
     REGISTER int indx;
     int nIndex;
     union {
-	unsigned char u_char[2];
-	unsigned short u_ushort;
+        unsigned char u_char[2];
+        unsigned short u_ushort;
     } val;
-    OBJ cls;
     unsigned char *byteP;
 
     if (__isSmallInteger(index)) {
-	indx = __intVal(index);
-	if (indx > 0) {
-	    if ((cls = __qClass(self)) != @global(ByteArray))
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    nIndex = __byteArraySize(self);
-	    if ((indx+1) <= nIndex) {
-		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
+        indx = __intVal(index);
+        if (indx > 0) {
+            if (!__isByteArrayLike(self))
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
+            nIndex = __byteArraySize(self);
+            if ((indx+1) <= nIndex) {
+                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
 #if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
-		val.u_ushort = ((unsigned short *)byteP)[0];
+                val.u_ushort = ((unsigned short *)byteP)[0];
 #else
-		/*
-		 * mhmh to be measured:
-		 *   the if may hurt more than the additional
-		 *   memory cycles on some machines ...
-		 */
-		if (((INT)byteP & 1) == 0) {
-		    /* aligned */
-		    val.u_ushort = ((unsigned short *)byteP)[0];
-		} else {
-		    val.u_char[0] = byteP[0];
-		    val.u_char[1] = byteP[1];
-		}
+                /*
+                 * mhmh to be measured:
+                 *   the if may hurt more than the additional
+                 *   memory cycles on some machines ...
+                 */
+                if (((INT)byteP & 1) == 0) {
+                    /* aligned */
+                    val.u_ushort = ((unsigned short *)byteP)[0];
+                } else {
+                    val.u_char[0] = byteP[0];
+                    val.u_char[1] = byteP[1];
+                }
 #endif
-		RETURN ( __mkSmallInteger((val.u_ushort)) );
-	    }
-	}
+                RETURN ( __mkSmallInteger((val.u_ushort)) );
+            }
+        }
     }
 %}.
     ^ super wordAt:index
@@ -713,67 +705,65 @@
     REGISTER int indx;
     int nIndex;
     int val;
-    OBJ cls;
     unsigned char *byteP;
 
     if (__isSmallInteger(index)) {
-	indx = __intVal(index);
-	if (indx > 0) {
-	    if ((cls = __qClass(self)) != @global(ByteArray))
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    nIndex = __byteArraySize(self);
-	    if ((indx+1) <= nIndex) {
-		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
-		if (msb == true) {
-		    /*
-		     * most significant byte first (i.e sparc order)
-		     */
+        indx = __intVal(index);
+        if (indx > 0) {
+            if (!__isByteArrayLike(self))
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
+            nIndex = __byteArraySize(self);
+            if ((indx+1) <= nIndex) {
+                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
+                if (msb == true) {
+                    /*
+                     * most significant byte first (i.e sparc order)
+                     */
 #if defined(__MSBFIRST__)
-		    /*
-		     * mhmh to be measured:
-		     *   the if may hurt more than the additional
-		     *   memory cycles on some machines ...
-		     */
-		    if (((INT)byteP & 1) == 0) {
-			/* aligned */
-			val = ((unsigned short *)byteP)[0];
-		    } else
+                    /*
+                     * mhmh to be measured:
+                     *   the if may hurt more than the additional
+                     *   memory cycles on some machines ...
+                     */
+                    if (((INT)byteP & 1) == 0) {
+                        /* aligned */
+                        val = ((unsigned short *)byteP)[0];
+                    } else
 #endif
-		    {
-			val = byteP[0];
-			val = (val << 8) + byteP[1];
-		    }
-		} else {
-		    /*
-		     * least significant byte first (i.e i386/alpha order)
-		     */
+                    {
+                        val = byteP[0];
+                        val = (val << 8) + byteP[1];
+                    }
+                } else {
+                    /*
+                     * least significant byte first (i.e i386/alpha order)
+                     */
 #if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
-		    val = ((unsigned short *)byteP)[0];
+                    val = ((unsigned short *)byteP)[0];
 #else
 # if defined(__LSBFIRST__)
-		    /*
-		     * mhmh to be measured:
-		     *   the if may hurt more than the additional
-		     *   memory cycles on some machines ...
-		     */
-		    if (((INT)byteP & 1) == 0) {
-			/* aligned */
-			val = ((unsigned short *)byteP)[0];
-		    } else
+                    /*
+                     * mhmh to be measured:
+                     *   the if may hurt more than the additional
+                     *   memory cycles on some machines ...
+                     */
+                    if (((INT)byteP & 1) == 0) {
+                        /* aligned */
+                        val = ((unsigned short *)byteP)[0];
+                    } else
 # endif
-		    {
-			val = byteP[1];
-			val = (val << 8) + byteP[0];
-		    }
+                    {
+                        val = byteP[1];
+                        val = (val << 8) + byteP[0];
+                    }
 #endif
-		}
-		RETURN ( __mkSmallInteger(val) );
-	    }
-	}
+                }
+                RETURN ( __mkSmallInteger(val) );
+            }
+        }
     }
 %}.
     ^ super wordAt:index MSB:msb
-
 !
 
 wordAt:index put:value
@@ -790,42 +780,41 @@
     int nIndex;
     int v;
     union {
-	unsigned char u_char[2];
-	unsigned short u_ushort;
+        unsigned char u_char[2];
+        unsigned short u_ushort;
     } val;
-    OBJ cls;
     unsigned char *byteP;
 
     if (__bothSmallInteger(index, value)) {
-	indx = __intVal(index);
-	if (indx > 0) {
-	    if ((cls = __qClass(self)) != @global(ByteArray))
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    nIndex = __byteArraySize(self);
-	    if ((indx+1) <= nIndex) {
-		val.u_ushort = v = __intVal(value);
-		if ((v & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
-		    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
+        indx = __intVal(index);
+        if (indx > 0) {
+            if (!__isByteArrayLike(self))
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
+            nIndex = __byteArraySize(self);
+            if ((indx+1) <= nIndex) {
+                val.u_ushort = v = __intVal(value);
+                if ((v & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
+                    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
 #if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
-		    ((unsigned short *)byteP)[0] = val.u_ushort;
+                    ((unsigned short *)byteP)[0] = val.u_ushort;
 #else
-		    /*
-		     * mhmh to be measured:
-		     *   the if may hurt more than the additional
-		     *   memory cycles on some machines ...
-		     */
-		    if (((INT)byteP & 1) == 0) {
-			/* aligned */
-			((unsigned short *)byteP)[0] = val.u_ushort;
-		    } else {
-			byteP[0] = val.u_char[0];
-			byteP[1] = val.u_char[1];
-		    }
+                    /*
+                     * mhmh to be measured:
+                     *   the if may hurt more than the additional
+                     *   memory cycles on some machines ...
+                     */
+                    if (((INT)byteP & 1) == 0) {
+                        /* aligned */
+                        ((unsigned short *)byteP)[0] = val.u_ushort;
+                    } else {
+                        byteP[0] = val.u_char[0];
+                        byteP[1] = val.u_char[1];
+                    }
 #endif
-		    RETURN ( value );
-		}
-	    }
-	}
+                    RETURN ( value );
+                }
+            }
+        }
     }
 %}.
     ^ super wordAt:index put:value
@@ -855,62 +844,62 @@
     unsigned char *byteP;
 
     if (__bothSmallInteger(index, value)) {
-	indx = __intVal(index);
-	if (indx > 0) {
-	    if ((cls = __qClass(self)) != @global(ByteArray))
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    nIndex = __byteArraySize(self);
-	    if ((indx+1) <= nIndex) {
-		val = __intVal(value);
-		if ((val & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
-		    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
-		    if (msb == true) {
-			/*
-			 * most significant byte first (i.e sparc order)
-			 */
+        indx = __intVal(index);
+        if (indx > 0) {
+            if (!__isByteArrayLike(self))
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
+            nIndex = __byteArraySize(self);
+            if ((indx+1) <= nIndex) {
+                val = __intVal(value);
+                if ((val & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
+                    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
+                    if (msb == true) {
+                        /*
+                         * most significant byte first (i.e sparc order)
+                         */
 #if defined(__MSBFIRST__)
-			/*
-			 * mhmh to be measured:
-			 *   the if may hurt more than the additional
-			 *   memory cycles on some machines ...
-			 */
-			if (((INT)byteP & 1) == 0) {
-			    /* aligned */
-			    ((unsigned short *)byteP)[0] = val;
-			} else
+                        /*
+                         * mhmh to be measured:
+                         *   the if may hurt more than the additional
+                         *   memory cycles on some machines ...
+                         */
+                        if (((INT)byteP & 1) == 0) {
+                            /* aligned */
+                            ((unsigned short *)byteP)[0] = val;
+                        } else
 #endif
-			{
-			    byteP[1] = val & 0xFF;
-			    byteP[0] = (val>>8) & 0xFF;
-			}
-		    } else {
-			/*
-			 * least significant byte first (i.e i386/alpha order)
-			 */
+                        {
+                            byteP[1] = val & 0xFF;
+                            byteP[0] = (val>>8) & 0xFF;
+                        }
+                    } else {
+                        /*
+                         * least significant byte first (i.e i386/alpha order)
+                         */
 #if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
-			((unsigned short *)byteP)[0] = val;
+                        ((unsigned short *)byteP)[0] = val;
 #else
 # if defined(__LSBFIRST__)
-			/*
-			 * mhmh to be measured:
-			 *   the if may hurt more than the additional
-			 *   memory cycles on some machines ...
-			 */
-			if (((INT)byteP & 1) == 0) {
-			    /* aligned */
-			    ((unsigned short *)byteP)[0] = val;
-			} else
+                        /*
+                         * mhmh to be measured:
+                         *   the if may hurt more than the additional
+                         *   memory cycles on some machines ...
+                         */
+                        if (((INT)byteP & 1) == 0) {
+                            /* aligned */
+                            ((unsigned short *)byteP)[0] = val;
+                        } else
 # endif
-			{
-			    byteP[0] = val & 0xFF;
-			    byteP[1] = (val>>8) & 0xFF;
-			}
+                        {
+                            byteP[0] = val & 0xFF;
+                            byteP[1] = (val>>8) & 0xFF;
+                        }
 #endif
-		    }
-		    RETURN ( value );
-		}
-	    }
-	}
+                    }
+                    RETURN ( value );
+                }
+            }
+        }
     }
 %}.
     ^ super wordAt:index put:value MSB:msb
@@ -1504,258 +1493,6 @@
      (ByteArray new:20) from:10 to:20 put:1
      (ByteArray new:20) from:1 to:10 put:1
     "
-!
-
-replaceBytesFrom:start to:stop with:aCollection startingAt:repStart
-    "replace elements from another collection, which must be a ByteArray-
-     like collection.
-
-     Notice: This operation modifies the receiver, NOT a copy;
-     therefore the change may affect all others referencing the receiver."
-
-%{  /* NOCONTEXT */
-
-    int nIndex, repNIndex;
-    int startIndex, stopIndex;
-    REGISTER unsigned char *src;
-    REGISTER int repStartIndex;
-    int repStopIndex, count;
-    REGISTER unsigned char *dst;
-    OBJ cls;
-
-#ifndef NO_PRIM_BYTEARR
-    if ((__isBytes(aCollection) || __isExternalBytesLike(aCollection))
-     && __isBytes(self)
-     && __bothSmallInteger(start, stop)
-     && __isSmallInteger(repStart)) {
-        startIndex = __intVal(start) - 1;
-        if (startIndex >= 0) {
-            dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex;
-            nIndex = __byteArraySize(self);
-
-            if ((cls = __qClass(self)) != @global(ByteArray)) {
-                int nInst;
-
-                nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-                dst += nInst;
-                nIndex -= nInst;
-            }
-
-            stopIndex = __intVal(stop) - 1;
-            count = stopIndex - startIndex + 1;
-            if (count == 0) {
-                RETURN ( self );
-            }
-
-            if ((count > 0) && (stopIndex < nIndex)) {
-                repStartIndex = __intVal(repStart) - 1;
-                if (repStartIndex >= 0) {
-                    if (__isExternalBytesLike(aCollection)) {
-                        OBJ sz;
-
-                        src = __externalAddressVal(aCollection);
-                        if (src == 0) goto fallBack;
-
-                        sz = __externalBytesSize(aCollection);
-                        if (__isSmallInteger(sz)) {
-                            repNIndex = __smallIntegerVal(sz);
-                        } else {
-                            repNIndex = repStopIndex+1; /* always enough */
-                        }
-                        src = src + repStartIndex;
-                    } else {
-                        if (__isString(aCollection)) {
-                            repNIndex = __stringSize(aCollection);
-                        } else {
-                            repNIndex = __qSize(aCollection) - OHDR_SIZE;
-                        }
-                        src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex;
-                        if ((cls = __qClass(aCollection)) != @global(ByteArray)) {
-                            int nInst;
-
-                            nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-                            src += nInst;
-                            repNIndex -= nInst;
-                        }
-                    }
-                    repStopIndex = repStartIndex + (stopIndex - startIndex);
-                    if (repStopIndex < repNIndex) {
-                        if (aCollection == self) {
-                            /* take care of overlapping copy */
-                            if (src < dst) {
-                                /* must do a reverse copy */
-                                src += count;
-                                dst += count;
-                                while (count-- > 0) {
-                                    *--dst = *--src;
-                                }
-                                RETURN ( self );
-                            }
-                        }
-
-# ifdef bcopy4
-                        if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) {
-                            int nW;
-
-                            /* copy unaligned part */
-                            while (count && ((unsigned INT)src & 3)) {
-                                *dst++ = *src++;
-                                count--;
-                            }
-
-                            if (count > 0) {
-                                /* copy aligned part */
-                                nW = count >> 2;
-                                bcopy4(src, dst, nW);
-                                if ((count = count & 3) != 0) {
-                                    /* copy any remaining part */
-                                    src += (nW<<2);
-                                    dst += (nW<<2);
-                                    while (count--) {
-                                        *dst++ = *src++;
-                                    }
-                                }
-                            }
-                            RETURN ( self );
-                        }
-# else
-#  if __POINTER_SIZE__ == 8
-                        if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) {
-                            /* copy unaligned part */
-                            while (count && ((unsigned INT)src & 7)) {
-                                *dst++ = *src++;
-                                count--;
-                            }
-
-                            /* copy aligned part */
-                            while (count >= 8) {
-                                ((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0];
-                                dst += 8;
-                                src += 8;
-                                count -= 8;
-                            }
-                            while (count--) {
-                                *dst++ = *src++;
-                            }
-                            RETURN ( self );
-                        }
-#  endif /* 64bit */
-# endif /* bcopy4 */
-
-# ifdef FAST_MEMCPY
-                        bcopy(src, dst, count);
-# else
-#  ifdef __UNROLL_LOOPS__
-                        while (count >= 8) {
-                            dst[0] = src[0]; dst[1] = src[1];
-                            dst[2] = src[2]; dst[3] = src[3];
-                            dst[4] = src[4]; dst[5] = src[5];
-                            dst[6] = src[6]; dst[7] = src[7];
-                            dst += 8; src += 8;
-                            count -= 8;
-                        }
-#  endif /* __UNROLL_LOOPS__ */
-                        while (count-- > 0) {
-                            *dst++ = *src++;
-                        }
-# endif
-                        RETURN ( self );
-                    }
-                }
-            }
-        }
-    }
-fallBack: ;
-#endif
-%}.
-    "
-     fall back in case of non-ByteArray argument,
-     or for the error report if any index is invalid
-    "
-    ^ super replaceBytesFrom:start to:stop with:aCollection startingAt:repStart
-
-    "
-     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-        copy
-            replaceFrom:1 to:8
-            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-            startingAt:1
-
-     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-        copy
-            replaceFrom:3 to:10
-            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-            startingAt:1
-
-     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-        copy
-            replaceFrom:3 to:4
-            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-            startingAt:1
-
-     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-        copy
-            replaceFrom:0 to:9
-            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-            startingAt:1
-
-     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-        copy
-            replaceFrom:1 to:10
-            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-            startingAt:0
-    "
-!
-
-replaceBytesFrom:startIndex with:replacementCollection startingAt:repStartIndex
-    "replace elements from another collection, which must be
-     byte-array-like.
-
-     Notice: This operation modifies the receiver, NOT a copy;
-     therefore the change may affect all others referencing the receiver."
-
-    ^ self
-	replaceBytesFrom:startIndex
-	to:(startIndex + replacementCollection size - repStartIndex)
-	with:replacementCollection
-	startingAt:repStartIndex
-
-    "
-     args:    startIndex            : <integer>
-	      replacementCollection : <collection of <bytes> >
-	      repStartIndex         : <integer>
-
-     returns: self
-    "
-
-    "Created: / 27.7.1998 / 16:56:46 / cg"
-    "Modified: / 27.7.1998 / 16:58:38 / cg"
-!
-
-replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
-    "replace elements in the receiver between index start and stop,
-     with elements  taken from replacementCollection starting at repStart.
-     Return the receiver.
-
-     Notice: This operation modifies the receiver, NOT a copy;
-     therefore the change may affect all others referencing the receiver."
-
-    ((aCollection class == self class)
-     or:[aCollection isByteCollection]) ifTrue:[
-        ^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
-    ].
-    ^ super replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
-
-    "
-     args:    startIndex            : <integer>
-              stopIndex             : <integer>
-              replacementCollection : <collection of <bytes> >
-              repStartIndex         : <integer>
-
-     returns: self
-    "
-
-    "Modified: / 27.7.1998 / 16:58:33 / cg"
 ! !
 
 !ByteArray methodsFor:'image manipulation support'!
@@ -2263,17 +2000,6 @@
     "
 !
 
-copyReverse
-    "create a copy of myself with elements reversed in order"
-
-    ^ self copy reverse
-
-    "
-     #[1 2 3 4 5] copyReverse
-     #[1 2 3 4] copyReverse
-    "
-!
-
 expandPixels:nBitsPerPixel width:width height:height into:aByteArray mapping:aMapByteArray
     "given the receiver with nBitsPerPixel-depth pixels, expand them into
      aByteArray with 8-bit pixels. The width/height-arguments are needed
@@ -3086,30 +2812,30 @@
     REGISTER int index;
     INT icounts[256];
 
-    if ((__qClass(self) == @global(ByteArray)) && __isArray(counts)) {
-	/*
-	 * zero counts
-	 */
-	for (index=0; index<256; index++) {
-	    icounts[index] = 0;
-	}
-
-	/*
-	 * count
-	 */
-	nByte = __qSize(self) - OHDR_SIZE;
-	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
-	while (nByte--) {
-	    icounts[*cp++]++;
-	}
-
-	/*
-	 * make it real counts
-	 */
-	for (index=0; index<256; index++) {
-	    __ArrayInstPtr(counts)->a_element[index] = __mkSmallInteger(icounts[index]);
-	}
-	RETURN ( counts );
+    if (__isByteArrayLike(self) && __isArray(counts)) {
+        /*
+         * zero counts
+         */
+        for (index=0; index<256; index++) {
+            icounts[index] = 0;
+        }
+
+        /*
+         * count
+         */
+        nByte = __qSize(self) - OHDR_SIZE;
+        cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
+        while (nByte--) {
+            icounts[*cp++]++;
+        }
+
+        /*
+         * make it real counts
+         */
+        for (index=0; index<256; index++) {
+            __ArrayInstPtr(counts)->a_element[index] = __mkSmallInteger(icounts[index]);
+        }
+        RETURN ( counts );
     }
 %}
 .
@@ -3132,62 +2858,62 @@
     REGISTER int len;
     OBJ result;
     union {
-	unsigned char flags[256];
-	int toForceAlignmentOfFlags;
+        unsigned char flags[256];
+        int toForceAlignmentOfFlags;
     } f;
 
 #ifdef TO_BE_MEASURED
     int coverage = 0;
 #endif
 
-    if (__qClass(self) == @global(ByteArray)) {
-	memset(f.flags, 0, sizeof(f.flags));
-	len = __qSize(self) - OHDR_SIZE;
-	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
-
-	/* for each used byte, set flag */
-	while (len > 0) {
+    if (__isByteArrayLike(self)) {
+        memset(f.flags, 0, sizeof(f.flags));
+        len = __qSize(self) - OHDR_SIZE;
+        cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
+
+        /* for each used byte, set flag */
+        while (len > 0) {
 #ifdef TO_BE_MEASURED
-	    unsigned  byte;
-
-	    byte = *cp;
-	    if (! f.flags[byte]) {
-		f.flags[byte] = 1;
-		coverage++;
-		if (coverage == 256) {
-		    /* no need to scan rest */
-		    break;
-		}
-	    }
+            unsigned  byte;
+
+            byte = *cp;
+            if (! f.flags[byte]) {
+                f.flags[byte] = 1;
+                coverage++;
+                if (coverage == 256) {
+                    /* no need to scan rest */
+                    break;
+                }
+            }
 #else
-	    f.flags[*cp] = 1;
+            f.flags[*cp] = 1;
 #endif
-	    cp++;
-	    len--;
-	}
-
-	/* count 1's */
-	len = 0;
-	for (cp=f.flags, endp=f.flags+256; cp < endp;) {
-	    if ( *((unsigned int *)cp)) {
-		if (cp[0]) len++;
-		if (cp[1]) len++;
-		if (cp[2]) len++;
-		if (cp[3]) len++;
-	    }
-	    cp += 4;
-	}
-
-	/* create ByteArray of used values */
-	result = __BYTEARRAY_UNINITIALIZED_NEW_INT(len);
-	if (result) {
-	    cp = __ByteArrayInstPtr(result)->ba_element;
-	    for (len=0; len < 256; len++) {
-		if (f.flags[len])
-		    *cp++ = len;
-	    }
-	    RETURN ( result );
-	}
+            cp++;
+            len--;
+        }
+
+        /* count 1's */
+        len = 0;
+        for (cp=f.flags, endp=f.flags+256; cp < endp;) {
+            if ( *((unsigned int *)cp)) {
+                if (cp[0]) len++;
+                if (cp[1]) len++;
+                if (cp[2]) len++;
+                if (cp[3]) len++;
+            }
+            cp += 4;
+        }
+
+        /* create ByteArray of used values */
+        result = __BYTEARRAY_UNINITIALIZED_NEW_INT(len);
+        if (result) {
+            cp = __ByteArrayInstPtr(result)->ba_element;
+            for (len=0; len < 256; len++) {
+                if (f.flags[len])
+                    *cp++ = len;
+            }
+            RETURN ( result );
+        }
     }
 %}.
     ^ self asIdentitySet asByteArray
@@ -3197,7 +2923,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'searching'!
 
 indexOf:aByte startingAt:start
@@ -3253,8 +2978,6 @@
     "
 ! !
 
-
-
 !ByteArray methodsFor:'testing'!
 
 isByteArray
@@ -3282,14 +3005,15 @@
 !ByteArray class methodsFor:'documentation'!
 
 version
-    ^ '$Id: ByteArray.st 10501 2010-02-13 23:34:44Z vranyj1 $'
+    ^ '$Id: ByteArray.st 10505 2010-03-08 21:39:02Z vranyj1 $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.199 2010/02/10 17:37:56 cg Exp §'
+    ^ '§Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.200 2010/03/08 07:42:51 stefan Exp §'
 ! !
 
 
 
 
 
+