--- a/ByteArray.st Wed Apr 20 11:32:15 2016 +0200
+++ b/ByteArray.st Wed Apr 20 12:54:38 2016 +0200
@@ -165,6 +165,7 @@
+
!ByteArray class methodsFor:'queries'!
elementByteSize
@@ -2332,7 +2333,7 @@
reverse
"reverse the order of my elements inplace -
WARNING: this is a destructive operation, which modifies the receiver.
- Please use reversed (with a d) for a functional version.
+ Please use reversed (with a 'd' at the end) for a functional version.
Written as a primitive for speed on image manipulations (mirror)"
%{ /* NOCONTEXT */
@@ -2343,98 +2344,98 @@
OBJ cls;
if (__qClass(self) == @global(ByteArray)) {
- cnt = __byteArraySize(self);
- p1 = __ByteArrayInstPtr(self)->ba_element;
- p2 = p1 + cnt - 1;
+ cnt = __byteArraySize(self);
+ p1 = __ByteArrayInstPtr(self)->ba_element;
+ p2 = p1 + cnt - 1;
#if defined(__BSWAP)
- /*
- * can we use the bswap instruction ?
- * notice - not all CPUs have it (the HAS_BSWAP checks this).
- */
- if (__HAS_BSWAP()
- && ((cnt & 3) == 0)) {
- unsigned int *ip1, *ip2;
-
- ip1 = (unsigned int *)p1;
- ip2 = (unsigned int *)(p2 - 3);
-
- ip2 -= 7;
- while (ip1 <= ip2) {
- int t1, t2;
-
- t1 = ip1[0];
- t2 = ip2[7];
- ip2[7] = __BSWAP(t1);
- ip1[0] = __BSWAP(t2);
-
- t1 = ip1[1];
- t2 = ip2[6];
- ip2[6] = __BSWAP(t1);
- ip1[1] = __BSWAP(t2);
-
- t1 = ip1[2];
- t2 = ip2[5];
- ip2[5] = __BSWAP(t1);
- ip1[2] = __BSWAP(t2);
-
- t1 = ip1[3];
- t2 = ip2[4];
- ip2[4] = __BSWAP(t1);
- ip1[3] = __BSWAP(t2);
-
- ip1 += 4;
- ip2 -= 4;
- }
- ip2 += 7;
-
- while (ip1 < ip2) {
- int t;
-
- t = __BSWAP(*ip1);
- *ip1++ = __BSWAP(*ip2);
- *ip2-- = t;
- }
-
- if (ip1 == ip2) {
- int t;
- t = *ip1;
- t = __BSWAP(t);
- *ip1 = t;
- }
- RETURN ( self );
- }
-#endif /* __i386__ && __GNUC__ */
-
- p2 -= 7;
- while (p1 <= p2) {
- t = p1[0];
- p1[0] = p2[7];
- p2[7] = t;
-
- t = p1[1];
- p1[1] = p2[6];
- p2[6] = t;
-
- t = p1[2];
- p1[2] = p2[5];
- p2[5] = t;
-
- t = p1[3];
- p1[3] = p2[4];
- p2[4] = t;
-
- p1 += 4;
- p2 -= 4;
- }
- p2 += 7;
-
- while (p1 < p2) {
- t = *p1;
- *p1++ = *p2;
- *p2-- = t;
- }
- RETURN ( self );
+ /*
+ * can we use the bswap instruction ?
+ * notice - not all CPUs have it (the HAS_BSWAP checks this).
+ */
+ if (__HAS_BSWAP()
+ && ((cnt & 3) == 0)) {
+ unsigned int *ip1, *ip2;
+
+ ip1 = (unsigned int *)p1;
+ ip2 = (unsigned int *)(p2 - 3);
+
+ ip2 -= 7;
+ while (ip1 <= ip2) {
+ int t1, t2;
+
+ t1 = ip1[0];
+ t2 = ip2[7];
+ ip2[7] = __BSWAP(t1);
+ ip1[0] = __BSWAP(t2);
+
+ t1 = ip1[1];
+ t2 = ip2[6];
+ ip2[6] = __BSWAP(t1);
+ ip1[1] = __BSWAP(t2);
+
+ t1 = ip1[2];
+ t2 = ip2[5];
+ ip2[5] = __BSWAP(t1);
+ ip1[2] = __BSWAP(t2);
+
+ t1 = ip1[3];
+ t2 = ip2[4];
+ ip2[4] = __BSWAP(t1);
+ ip1[3] = __BSWAP(t2);
+
+ ip1 += 4;
+ ip2 -= 4;
+ }
+ ip2 += 7;
+
+ while (ip1 < ip2) {
+ int t;
+
+ t = __BSWAP(*ip1);
+ *ip1++ = __BSWAP(*ip2);
+ *ip2-- = t;
+ }
+
+ if (ip1 == ip2) {
+ int t;
+ t = *ip1;
+ t = __BSWAP(t);
+ *ip1 = t;
+ }
+ RETURN ( self );
+ }
+#endif /* __BSWAP (i.e. __i386__ && __GNUC__) */
+
+ p2 -= 7;
+ while (p1 <= p2) {
+ t = p1[0];
+ p1[0] = p2[7];
+ p2[7] = t;
+
+ t = p1[1];
+ p1[1] = p2[6];
+ p2[6] = t;
+
+ t = p1[2];
+ p1[2] = p2[5];
+ p2[5] = t;
+
+ t = p1[3];
+ p1[3] = p2[4];
+ p2[4] = t;
+
+ p1 += 4;
+ p2 -= 4;
+ }
+ p2 += 7;
+
+ while (p1 < p2) {
+ t = *p1;
+ *p1++ = *p2;
+ *p2-- = t;
+ }
+ RETURN ( self );
}
%}.
^ super reverse
@@ -2454,32 +2455,32 @@
(1 to:255) asByteArray reverse
1 to:1024 do:[:i|
- |bytes test rBytes|
-
- bytes := ((1 to:i) asArray collect:[:i | i bitAnd:255]) asByteArray.
- test := ((i to:1 by:-1) asArray collect:[:i | i bitAnd:255]) asByteArray.
- rBytes := bytes copy.
- rBytes reverse ~= test ifTrue:[
- self halt
- ].
- rBytes := bytes copy.
- rBytes reverse reverse ~= bytes ifTrue:[
- self halt
- ]
+ |bytes test rBytes|
+
+ bytes := ((1 to:i) asArray collect:[:i | i bitAnd:255]) asByteArray.
+ test := ((i to:1 by:-1) asArray collect:[:i | i bitAnd:255]) asByteArray.
+ rBytes := bytes copy.
+ rBytes reverse ~= test ifTrue:[
+ self halt
+ ].
+ rBytes := bytes copy.
+ rBytes reverse reverse ~= bytes ifTrue:[
+ self halt
+ ]
].
Time millisecondsToRun:[
- 10000000 timesRepeat:[
- #[1 2 3 4 5 6 7 8] reverse
- ]
+ 10000000 timesRepeat:[
+ #[1 2 3 4 5 6 7 8] reverse
+ ]
]
|b|
b := (0 to:255) asByteArray.
Time millisecondsToRun:[
- 10000000 timesRepeat:[
- b reverse
- ]
+ 10000000 timesRepeat:[
+ b reverse
+ ]
]
"
!
@@ -3062,7 +3063,6 @@
"
! !
-
!ByteArray methodsFor:'testing'!
isByteArray
@@ -3087,6 +3087,7 @@
"Modified: 22.4.1996 / 12:55:30 / cg"
! !
+
!ByteArray class methodsFor:'documentation'!
version