--- a/ByteArray.st Tue Oct 26 15:29:24 1999 +0200
+++ b/ByteArray.st Tue Oct 26 20:34:14 1999 +0200
@@ -1133,9 +1133,9 @@
#ifdef bcopy4
if (((unsigned INT)srcp & 3) == ((unsigned INT)dstp & 3)) {
+ int nW;
+
/* copy unaligned part */
- int nW;
-
while (count && (((unsigned INT)srcp & 3) != 0)) {
*dstp++ = *srcp++;
count--;
@@ -1151,6 +1151,30 @@
RETURN ( newByteArray );
}
#endif /* bcopy4 */
+#ifdef alpha64
+ 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);
@@ -1174,6 +1198,9 @@
"
#[1 2 3 4 5 6 7 8 9 10] copyFrom:1 to:10
#[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:7
+ #[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:11
+ #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:10
+ #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:9
"
!
@@ -1253,68 +1280,70 @@
if (__isSmallInteger(aNumber)
&& __bothSmallInteger(start, stop)
&& __isBytes(self)) {
- len = __byteArraySize(self);
- index1 = __intVal(start);
- index2 = __intVal(stop);
-
- dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
- if ((cls = __qClass(self)) != @global(ByteArray)) {
- int nInst;
-
- nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- dstp += nInst;
- len -= nInst;
- }
-
- value = __intVal(aNumber);
- if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */
- && (index1 <= index2)
- && (index1 > 0)) {
- if (index2 <= len) {
- count = index2 - index1 + 1;
+ len = __byteArraySize(self);
+ index1 = __intVal(start);
+ index2 = __intVal(stop);
+
+ dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
+ if ((cls = __qClass(self)) != @global(ByteArray)) {
+ int nInst;
+
+ nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ dstp += nInst;
+ len -= nInst;
+ }
+
+ value = __intVal(aNumber);
+ if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */
+ && (index1 <= index2)
+ && (index1 > 0)) {
+ if (index2 <= len) {
+ count = index2 - index1 + 1;
#ifdef memset4
- if (count > 20) {
- while (((unsigned INT)dstp & 3) != 0) {
- *dstp++ = value;
- count--;
- }
- {
- int n4 = count & ~3;
- int v4, nW;
-
- v4 = (value << 8) | value;
- v4 = (v4 << 16) | v4;
- nW = n4>>2;
- memset4(dstp, v4, nW);
- count -= n4;
- dstp += n4;
- }
- while (count--) {
- *dstp++ = value;
- }
- RETURN (self);
- }
+ if (count > 20) {
+ /* fill unaligned part */
+ while (((unsigned INT)dstp & 3) != 0) {
+ *dstp++ = value;
+ count--;
+ }
+ /* fill aligned part */
+ {
+ int n4 = count & ~3;
+ int v4, nW;
+
+ v4 = (value << 8) | value;
+ v4 = (v4 << 16) | v4;
+ nW = n4>>2;
+ memset4(dstp, v4, nW);
+ count -= n4;
+ dstp += n4;
+ }
+ while (count--) {
+ *dstp++ = value;
+ }
+ RETURN (self);
+ }
#endif /* memset4 */
#ifdef FAST_MEMSET
- memset(dstp, value, count);
+ memset(dstp, value, count);
#else
# ifdef UNROLL_LOOPS
- while (count >= 8) {
- dstp[0] = dstp[1] = dstp[2] = dstp[3] =
- dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
- dstp += 8;
- count -= 8;
- }
+ while (count >= 8) {
+ dstp[0] = dstp[1] = dstp[2] = dstp[3] =
+ dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
+ dstp += 8;
+ count -= 8;
+ }
# endif /* UNROLL_LOOPS */
- while (count--) {
- *dstp++ = value;
- }
+ while (count--) {
+ *dstp++ = value;
+ }
#endif
- RETURN (self);
- }
- }
+ RETURN (self);
+ }
+ }
}
%}.
"
@@ -1346,113 +1375,124 @@
&& __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) {
- 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) {
+ 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) == 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 );
- }
+ 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
# ifdef alpha64
- if ((((unsigned INT)src & 7) == 0)
- && (((unsigned INT)dst & 7) == 0)) {
- /* copy aligned part */
- int nW = count >> 3;
-
- 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 /* alpha64 */
#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
%}.
@@ -1461,6 +1501,38 @@
or for the error report if any index is invalid
"
^ super replaceFrom: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
@@ -2736,5 +2808,5 @@
!ByteArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.128 1999-10-26 12:19:38 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.129 1999-10-26 18:34:14 cg Exp $'
! !