class: Array
authorStefan Vogel <sv@exept.de>
Tue, 14 Jul 2015 15:04:16 +0200
changeset 18579 3dedfc433f6a
parent 18578 dd44b8acf863
child 18580 5bdec8c6f5f2
class: Array changed: #replaceFrom:to:with:startingAt: use memcpy() instead of obsolete bcopy()
Array.st
--- a/Array.st	Tue Jul 14 15:03:29 2015 +0200
+++ b/Array.st	Tue Jul 14 15:04:16 2015 +0200
@@ -1619,142 +1619,138 @@
     OBJ myClass;
 
     if (
-	(__ClassInstPtr((myClass = __qClass(self)))->c_ninstvars == __mkSmallInteger(0))
+        (__ClassInstPtr((myClass = __qClass(self)))->c_ninstvars == __mkSmallInteger(0))
      && __isNonNilObject(aCollection)
      && (((t = __qClass(aCollection)) == Array) || (t == myClass))
      && __bothSmallInteger(start, stop)
      && __isSmallInteger(repStart)
     ) {
-	startIndex = __intVal(start) - 1;
-	if (startIndex >= 0) {
-	    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
-	    stopIndex = __intVal(stop) - 1;
-	    count = stopIndex - startIndex + 1;
+        startIndex = __intVal(start) - 1;
+        if (startIndex >= 0) {
+            nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+            stopIndex = __intVal(stop) - 1;
+            count = stopIndex - startIndex + 1;
 
-	    if ((count > 0) && (stopIndex < nIndex)) {
-		repStartIndex = __intVal(repStart) - 1;
-		if (repStartIndex >= 0) {
-		    repNIndex = __BYTES2OBJS__(__qSize(aCollection)-OHDR_SIZE);
-		    repStopIndex = repStartIndex + (stopIndex - startIndex);
-		    if (repStopIndex < repNIndex) {
-			src = &(__InstPtr(aCollection)->i_instvars[repStartIndex]);
-			dst = &(__InstPtr(self)->i_instvars[startIndex]);
-			if (aCollection == self) {
-			    /*
-			     * no need to check stores if copying
-			     * from myself
-			     */
+            if ((count > 0) && (stopIndex < nIndex)) {
+                repStartIndex = __intVal(repStart) - 1;
+                if (repStartIndex >= 0) {
+                    repNIndex = __BYTES2OBJS__(__qSize(aCollection)-OHDR_SIZE);
+                    repStopIndex = repStartIndex + (stopIndex - startIndex);
+                    if (repStopIndex < repNIndex) {
+                        src = &(__InstPtr(aCollection)->i_instvars[repStartIndex]);
+                        dst = &(__InstPtr(self)->i_instvars[startIndex]);
+                        if (aCollection == self) {
+                            /*
+                             * no need to check stores if copying
+                             * from myself
+                             */
 
-			    /*
-			     * take care of overlapping copy
-			     * do not depend on memset being smart enough
-			     * (some are not ;-)
-			     */
-			    if (src < dst) {
-				/* must do a reverse copy */
-				src += count;
-				dst += count;
+                            /*
+                             * take care of overlapping copy
+                             * do not depend on memset being smart enough
+                             * (some are not ;-)
+                             */
+                            if (src < dst) {
+                                /* must do a reverse copy */
+                                src += count;
+                                dst += count;
 #ifdef __UNROLL_LOOPS__
-				while (count > 8) {
-				    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];
-				    dst -= 8; src -= 8;
-				    count -= 8;
-				}
+                                while (count > 8) {
+                                    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];
+                                    dst -= 8; src -= 8;
+                                    count -= 8;
+                                }
 #endif
-				while (count-- > 0) {
-				    *--dst = *--src;
-				}
-				RETURN ( self );
-			    }
+                                while (count-- > 0) {
+                                    *--dst = *--src;
+                                }
+                                RETURN ( self );
+                            }
 #ifdef SOFTWARE_PIPELINE
-			    {
-				OBJ t1;
-
-				/*
-				 * the loop below fetches one longWord behind
-				 * this should not be a problem
-				 */
-				t1 = src[0];
-				count--;
-				if (count) {
-				    dst++; src++;
-				    do {
-					dst[-1] = t1;
-					t1 = src[0];
-					src++;
-					dst++;
-				    } while (count--);
-				} else {
-				    dst[0] = t1;
-				}
-			    }
+                            {
+                                /*
+                                 * the loop below fetches one longWord behind
+                                 * this should not be a problem
+                                 */
+                                OBJ t1 = src[0];
+                                count--;
+                                if (count) {
+                                    dst++; src++;
+                                    do {
+                                        dst[-1] = t1;
+                                        t1 = src[0];
+                                        src++;
+                                        dst++;
+                                    } while (count--);
+                                } else {
+                                    dst[0] = t1;
+                                }
+                            }
 #else
 
 # ifdef bcopy4
-			    bcopy4(src, dst, count);
+                            bcopy4(src, dst, count);
 # else
 #  ifdef FAST_MEMCPY
-			    bcopy(src, dst, __OBJS2BYTES__(count));
+                            memcpy(dst, src, __OBJS2BYTES__(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
-			    while (count--) {
-				*dst++ = *src++;
-			    }
+                            while (count--) {
+                                *dst++ = *src++;
+                            }
 #  endif
 # endif
 #endif
-			} else {
-			    REGISTER int spc;
-
-			    spc = __qSpace(self);
+                        } else {
+                            REGISTER int spc = __qSpace(self);
 #ifdef __UNROLL_LOOPS__
-			    while (count >= 8) {
-				t = src[0]; dst[0] = t; __STORE_SPC(self, t, spc);
-				t = src[1]; dst[1] = t; __STORE_SPC(self, t, spc);
-				t = src[2]; dst[2] = t; __STORE_SPC(self, t, spc);
-				t = src[3]; dst[3] = t; __STORE_SPC(self, t, spc);
-				t = src[4]; dst[4] = t; __STORE_SPC(self, t, spc);
-				t = src[5]; dst[5] = t; __STORE_SPC(self, t, spc);
-				t = src[6]; dst[6] = t; __STORE_SPC(self, t, spc);
-				t = src[7]; dst[7] = t; __STORE_SPC(self, t, spc);
-				count -= 8; src += 8; dst += 8;
-			    }
+                            while (count >= 8) {
+                                t = src[0]; dst[0] = t; __STORE_SPC(self, t, spc);
+                                t = src[1]; dst[1] = t; __STORE_SPC(self, t, spc);
+                                t = src[2]; dst[2] = t; __STORE_SPC(self, t, spc);
+                                t = src[3]; dst[3] = t; __STORE_SPC(self, t, spc);
+                                t = src[4]; dst[4] = t; __STORE_SPC(self, t, spc);
+                                t = src[5]; dst[5] = t; __STORE_SPC(self, t, spc);
+                                t = src[6]; dst[6] = t; __STORE_SPC(self, t, spc);
+                                t = src[7]; dst[7] = t; __STORE_SPC(self, t, spc);
+                                count -= 8; src += 8; dst += 8;
+                            }
 #endif
-			    while (count-- > 0) {
-				t = *src++;
-				*dst++ = t;
-				__STORE_SPC(self, t, spc);
-			    }
-			}
-			RETURN ( self );
-		    }
-		}
-	    }
+                            while (count-- > 0) {
+                                t = *src++;
+                                *dst++ = t;
+                                __STORE_SPC(self, t, spc);
+                            }
+                        }
+                        RETURN ( self );
+                    }
+                }
+            }
 
-	    if (count == 0) {
-		RETURN ( self );
-	    }
-	}
+            if (count == 0) {
+                RETURN ( self );
+            }
+        }
     }
 %}.
     ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
@@ -2688,9 +2684,10 @@
 !Array class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.172 2015-05-26 18:55:30 cg Exp $'
+    ^ '$Header$'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.172 2015-05-26 18:55:30 cg Exp $'
+    ^ '$Header$'
 ! !
+