--- a/ByteArray.st Tue Jun 10 12:59:59 2003 +0200
+++ b/ByteArray.st Tue Jun 10 13:07:53 2003 +0200
@@ -2595,7 +2595,8 @@
reverse
"reverse the order of my elements inplace -
- written as a primitive for speed on image manipulations (mirror)"
+ WARNING: this is a destructive operation, which modifies the receiver.
+ Written as a primitive for speed on image manipulations (mirror)"
%{ /* NOCONTEXT */
@@ -2605,98 +2606,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 );
- }
+ /*
+ * 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 );
+ 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
@@ -2716,32 +2717,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
+ ]
]
"
!
@@ -3284,5 +3285,5 @@
!ByteArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.156 2003-04-29 13:41:17 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.157 2003-06-10 11:07:53 cg Exp $'
! !
--- a/String.st Tue Jun 10 12:59:59 2003 +0200
+++ b/String.st Tue Jun 10 13:07:53 2003 +0200
@@ -312,8 +312,6 @@
^ self basicNew:anInteger
! !
-
-
!String class methodsFor:'Compatibility-Squeak'!
cr
@@ -383,8 +381,6 @@
"Modified: 23.4.1996 / 16:00:38 / cg"
! !
-
-
!String methodsFor:'accessing'!
at:index
@@ -2299,7 +2295,8 @@
!
reverse
- "in-place reverse the characters of the string."
+ "in-place reverse the characters of the string.
+ WARNING: this is a destructive operation, which modifies the receiver."
"Q: is there a need to redefine it here ?"
@@ -2309,16 +2306,16 @@
REGISTER unsigned char *hip, *lowp;
if (__isString(self)) {
- lowp = __stringVal(self);
- hip = lowp + __stringSize(self) - 1;
- while (lowp < hip) {
- c = *lowp;
- *lowp = *hip;
- *hip = c;
- lowp++;
- hip--;
- }
- RETURN ( self );
+ lowp = __stringVal(self);
+ hip = lowp + __stringSize(self) - 1;
+ while (lowp < hip) {
+ c = *lowp;
+ *lowp = *hip;
+ *hip = c;
+ lowp++;
+ hip--;
+ }
+ RETURN ( self );
}
%}.
^ super reverse
@@ -3067,5 +3064,5 @@
!String class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.183 2003-05-19 11:14:24 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.184 2003-06-10 11:07:09 cg Exp $'
! !