oops - replaceBytesFrom:to:with:startingAt: was wrong for Strings (inherited)
authorClaus Gittinger <cg@exept.de>
Mon, 14 Jul 2008 21:29:33 +0200
changeset 11078 37a8b2522762
parent 11077 14df4640ed89
child 11079 cd8abd9e87a7
oops - replaceBytesFrom:to:with:startingAt: was wrong for Strings (inherited)
ByteArray.st
--- a/ByteArray.st	Mon Jul 14 13:24:25 2008 +0200
+++ b/ByteArray.st	Mon Jul 14 21:29:33 2008 +0200
@@ -161,7 +161,6 @@
     ^ self basicNew:anInteger
 ! !
 
-
 !ByteArray class methodsFor:'queries'!
 
 isBuiltInClass
@@ -909,7 +908,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'comparing'!
 
 = aByteArray
@@ -1460,138 +1458,142 @@
      && __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 {
-			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 );
-			    }
-			}
+        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) - OHDR_SIZE;
+                        } 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 );
-			}
+                        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 );
-			}
+                        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);
+                        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;
-			}
+                        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++;
-			}
+                        while (count-- > 0) {
+                            *dst++ = *src++;
+                        }
 # endif
-			RETURN ( self );
-		    }
-		}
-	    }
-	}
+                        RETURN ( self );
+                    }
+                }
+            }
+        }
     }
 fallBack: ;
 #endif
@@ -1604,34 +1606,34 @@
 
     "
      #[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
+        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
+        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
+        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
+        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
+        copy
+            replaceFrom:1 to:10
+            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+            startingAt:0
     "
 !
 
@@ -3113,7 +3115,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'searching'!
 
 indexOf:aByte startingAt:start
@@ -3196,5 +3197,5 @@
 !ByteArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.182 2008-06-24 13:33:45 fm Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.183 2008-07-14 19:29:33 cg Exp $'
 ! !