diff -r 79888b6f4b20 -r 58d5c0f8d906 ByteArray.st --- a/ByteArray.st Mon May 27 10:08:41 2013 +0200 +++ b/ByteArray.st Mon May 27 10:10:49 2013 +0200 @@ -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 " ! @@ -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.209 2013-05-27 08:10:49 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.209 2013-05-27 08:10:49 cg Exp $' ! ! +