--- a/ByteArray.st Tue May 28 00:23:55 2013 +0100
+++ b/ByteArray.st Fri May 31 00:35:21 2013 +0100
@@ -162,6 +162,9 @@
! !
+
+
+
!ByteArray class methodsFor:'queries'!
elementByteSize
@@ -179,6 +182,8 @@
"Modified: 23.4.1996 / 15:56:25 / cg"
! !
+
+
!ByteArray methodsFor:'Compatibility-Squeak'!
bitXor:aByteArray
@@ -2381,7 +2386,9 @@
swapBytes
"swap bytes inplace -
- written as a primitive for speed on image grabbing (if display order is different)"
+ Expects that the receiver has an even number of bytes;
+ if not, only the pairs excluding the last byte are swapped.
+ written as a primitive for speed on image grabbing (if display order is different)."
%{ /* NOCONTEXT */
@@ -2390,32 +2397,40 @@
REGISTER unsigned t;
if (__qClass(self) == @global(ByteArray)) {
- cnt = __byteArraySize(self);
- cnt = cnt & ~1; /* make it even */
- p = __ByteArrayInstPtr(self)->ba_element;
- while (cnt > 0) {
-#ifdef OLD
- t = p[0];
- p[0] = p[1];
- p[1] = t;
+ cnt = __byteArraySize(self);
+ cnt = cnt & ~1; /* make it even */
+ p = __ByteArrayInstPtr(self)->ba_element;
+
+ while (cnt >= sizeof(INT)) {
+ unsigned INT i = ((unsigned INT *)p)[0];
+
+#if __POINTER_SIZE__ == 8
+ i = ((i>>8) & 0x00FF00FF00FF00FF) | ((i & 0x00FF00FF00FF00FF) << 8);
#else
- unsigned short s;
-
- s = ((unsigned short *)p)[0];
- s = (s >> 8) | (s << 8);
- ((unsigned short *)p)[0] = s;
-#endif
- p += 2;
- cnt -= 2;
- }
- RETURN ( self );
+ i = ((i>>8) & 0x00FF00FF) | ((i & 0x00FF00FF) << 8);
+#endif /* __POINTER_SIZE__ */
+ ((unsigned INT *)p)[0] = i;
+ p += sizeof(INT);
+ cnt -= sizeof(INT);
+ }
+ while (cnt > 0) {
+ unsigned short s;
+
+ s = ((unsigned short *)p)[0];
+ s = (s >> 8) | (s << 8);
+ ((unsigned short *)p)[0] = s;
+ p += 2;
+ cnt -= 2;
+ }
+ RETURN ( self );
}
%}.
^ super swapBytes "/ rubbish - there is no one currenly
"
- #[1 2 3 4 5 6 7 8 9 10] copy swapBytes
- #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes
+ #[1 2 3 4 5 6 7 8 9 10] copy swapBytes -> #[2 1 4 3 6 5 8 7 10 9]
+ #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes -> #[2 1 4 3 6 5 8 7 10 9 11]
+ #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] copy swapBytes
"
!
@@ -2426,20 +2441,20 @@
REGISTER unsigned char *p;
unsigned int __i1, __i2;
- int cnt;
+ int sz;
unsigned int t;
if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) {
- __i1 = __intVal(i1) - 1;
- __i2 = __intVal(i2) - 1;
- cnt = __byteArraySize(self);
- p = __ByteArrayInstPtr(self)->ba_element;
- if (__i1 < cnt && __i2 < cnt) {
- t = p[__i1];
- p[__i1] = p[__i2];
- p[__i2] = t;
- }
- RETURN ( self );
+ __i1 = __intVal(i1) - 1;
+ __i2 = __intVal(i2) - 1;
+ sz = __byteArraySize(self);
+ p = __ByteArrayInstPtr(self)->ba_element;
+ if (__i1 < sz && __i2 < sz) {
+ t = p[__i1];
+ p[__i1] = p[__i2];
+ p[__i2] = t;
+ }
+ RETURN ( self );
}
%}.
^ super swapIndex:i1 and:i2 "/ rubbish - there is no one currently
@@ -2908,6 +2923,7 @@
"
! !
+
!ByteArray methodsFor:'searching'!
indexOf:aByte startingAt:start
@@ -2973,6 +2989,7 @@
"
! !
+
!ByteArray methodsFor:'testing'!
isByteArray
@@ -3000,9 +3017,10 @@
!ByteArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.208 2012-10-10 17:00:30 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.210 2013-05-27 08:23:00 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.208 2012-10-10 17:00:30 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.210 2013-05-27 08:23:00 cg Exp $'
! !
+