ByteArray.st
changeset 3676 140bdb21d859
parent 3425 f7faef75f0d8
child 3685 04fd42507276
--- a/ByteArray.st	Mon Jul 27 11:37:48 1998 +0200
+++ b/ByteArray.st	Mon Jul 27 16:59:49 1998 +0200
@@ -1212,8 +1212,11 @@
 !
 
 replaceBytesFrom:start to:stop with:aCollection startingAt:repStart
-    "replace elements from another collection, which must be a ByteArray
-     or String."
+    "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 */
 
@@ -1230,94 +1233,94 @@
      && __isBytes(self)
      && __bothSmallInteger(start, stop)
      && __isSmallInteger(repStart)) {
-	startIndex = __intVal(start) - 1;
-	if (startIndex >= 0) {
-	    dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex;
-	    nIndex = __byteArraySize(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;
+            if ((cls = __qClass(self)) != @global(ByteArray)) {
+                int nInst;
 
-		nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-		dst += nInst;
-		nIndex -= 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 );
-	    }
+            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) {
-		    repNIndex = __qSize(aCollection) - OHDR_SIZE;
-		    src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex;
-		    if ((cls = __qClass(aCollection)) != @global(ByteArray)) {
-			int nInst;
+            if ((count > 0) && (stopIndex < nIndex)) {
+                repStartIndex = __intVal(repStart) - 1;
+                if (repStartIndex >= 0) {
+                    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;
-		    }
+                        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 );
-			    }
-			}
+                    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) == 0)
-			 && (((unsigned INT)dst & 3) == 0)) {
-			    /* copy aligned part */
-			    int nW = count >> 2;
+                        if ((((unsigned INT)src & 3) == 0)
+                         && (((unsigned INT)dst & 3) == 0)) {
+                            /* copy aligned part */
+                            int 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 );
-			}
+                            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 );
+                        }
 #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 );
+                    }
+                }
+            }
+        }
     }
 #endif
 %}.
@@ -1328,17 +1331,54 @@
     ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
 !
 
-replaceFrom:start to:stop with:aCollection startingAt:repStart
+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."
+     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) ifTrue:[
-        ^ self replaceBytesFrom:start to:stop with:aCollection startingAt:repStart
+        ^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
     ].
-    ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
+    ^ super replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
 
-    "Modified: / 28.1.1998 / 16:48:46 / cg"
+    "
+     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'!
@@ -2123,5 +2163,5 @@
 !ByteArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.99 1998-05-08 10:29:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.100 1998-07-27 14:59:49 cg Exp $'
 ! !