ByteArray.st
branchjv
changeset 17976 50c2416f962a
parent 17911 a99f15c5efa5
child 18011 deb0c3355881
--- a/ByteArray.st	Mon Oct 29 17:05:17 2012 +0000
+++ b/ByteArray.st	Mon Oct 29 22:07:56 2012 +0000
@@ -11,7 +11,7 @@
 "
 "{ Package: 'stx:libbasic' }"
 
-UninterpretedBytes variableByteSubclass:#ByteArray
+UninterpretedBytes subclass:#ByteArray
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
@@ -161,9 +161,6 @@
     ^ self basicNew:anInteger
 ! !
 
-
-
-
 !ByteArray class methodsFor:'queries'!
 
 elementByteSize
@@ -181,8 +178,6 @@
     "Modified: 23.4.1996 / 15:56:25 / cg"
 ! !
 
-
-
 !ByteArray methodsFor:'Compatibility-Squeak'!
 
 bitXor:aByteArray
@@ -925,7 +920,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'comparing'!
 
 = aByteArray
@@ -2543,7 +2537,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'printing & storing'!
 
 displayOn:aGCOrStream
@@ -2912,7 +2905,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'searching'!
 
 indexOf:aByte startingAt:start
@@ -2929,36 +2921,46 @@
     OBJ cls;
 
     if (__isSmallInteger(aByte) &&__isBytes(self)) {
-	byteValue = __intVal(aByte);
-
-	if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
-	    /*
-	     * searching for something which cannot be found
-	     */
-	    RETURN ( __mkSmallInteger(0) );
-	}
-
-	if (__isSmallInteger(start)) {
-	    index = __intVal(start);
-	    len = __byteArraySize(self);
-	    cp = __ByteArrayInstPtr(self)->ba_element;
-	    if ((cls = __qClass(self)) != @global(ByteArray)) {
-		int nInst;
-
-		nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-		cp += nInst;
-		len -= nInst;
-	    }
-	    cp += index - 1;
-	    while (index <= len) {
-		if (*cp == byteValue) {
-		    RETURN ( __mkSmallInteger(index) );
-		}
-		index++;
-		cp++;
-	    }
-	    RETURN ( __mkSmallInteger(0) );
-	}
+        byteValue = __intVal(aByte);
+
+        if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
+            /*
+             * searching for something which cannot be found
+             */
+            RETURN ( __mkSmallInteger(0) );
+        }
+
+        if (__isSmallInteger(start)) {
+            index = __intVal(start);
+            len = __byteArraySize(self);
+            cp = __ByteArrayInstPtr(self)->ba_element;
+            if ((cls = __qClass(self)) != @global(ByteArray)) {
+                int nInst;
+
+                nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+                cp += nInst;
+                len -= nInst;
+            }
+            cp += index - 1;
+#ifdef __UNROLL_LOOPS__
+            while ((index+4) < len) {
+                if (cp[0] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
+                if (cp[1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
+                if (cp[2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
+                if (cp[3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
+                index += 4;
+                cp += 4;
+            }
+#endif
+            while (index <= len) {
+                if (*cp == byteValue) {
+                    RETURN ( __mkSmallInteger(index) );
+                }
+                index++;
+                cp++;
+            }
+            RETURN ( __mkSmallInteger(0) );
+        }
     }
 %}.
     ^ super indexOf:aByte startingAt:start
@@ -2968,7 +2970,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'testing'!
 
 isByteArray
@@ -2996,16 +2997,13 @@
 !ByteArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.206 2011/09/15 13:11:51 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.208 2012/10/10 17:00:30 cg Exp $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.206 2011/09/15 13:11:51 cg Exp §'
+    ^ '§Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.208 2012/10/10 17:00:30 cg Exp §'
 !
 
 version_SVN
-    ^ '$Id: ByteArray.st 10761 2012-01-19 11:46:00Z vranyj1 $'
+    ^ '$Id: ByteArray.st 10858 2012-10-29 22:07:56Z vranyj1 $'
 ! !
-
-
-