Array.st
changeset 945 b2a1dc200c42
parent 835 8bd6f4aa8130
child 946 35962f2a169b
--- a/Array.st	Thu Feb 08 22:04:21 1996 +0100
+++ b/Array.st	Thu Feb 08 22:19:06 1996 +0100
@@ -465,7 +465,9 @@
     "evaluate the argument, aBlock for each element in the collection.
      - reimplemented for speed"
 
-    |home|
+    |home sz "{ Class: SmallInteger }"|
+
+    sz := self size.
 %{
     REGISTER OBJFUNC codeVal;
     REGISTER int index;
@@ -473,8 +475,12 @@
     static struct inlineCache val = _ILC1;
     REGISTER OBJ rHome;
 
-    index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
+    index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
+/*
     nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+*/
+    nIndex = index + __intVal(sz);
+
     if (__isBlockLike(aBlock)
      && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
      && (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) {
@@ -491,7 +497,7 @@
 	    /*
 	     * home will not move - keep in a fast register
 	     */
-#if defined(UNROLL_LOOPS)
+# if defined(UNROLL_LOOPS)
 	    {
 		int i4;
 
@@ -507,7 +513,7 @@
 		    index = i4;
 		}
 	    }
-#endif
+# endif
 	    for (; index < nIndex; index++) {
 		if (InterruptPending != nil) __interruptL(@line COMMA_CON);
 
@@ -531,8 +537,7 @@
 			    _InstPtr(self)->i_instvars[index]);
 	} 
     }
-%}
-.
+%}.
     ^ self
 !
 
@@ -576,7 +581,7 @@
 		    rHome = home;
 		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) {
 			index = indexLow;
-#if defined(UNROLL_LOOPS)
+# if defined(UNROLL_LOOPS)
 			{
 			    int i4;
 
@@ -592,7 +597,7 @@
 				index = i4;
 			    }
 			}
-#endif
+# endif
 			for (; index <= indexHigh; index++) {
 			    if (InterruptPending != nil) __interruptL(@line COMMA_CON);
 			    (*codeVal)(rHome, CON_COMMA  _InstPtr(self)->i_instvars[index]);
@@ -617,8 +622,7 @@
 	    RETURN ( self );
 	}
     }
-%}
-.
+%}.
     ^ super from:start to:stop do:aBlock
 !
 
@@ -681,8 +685,7 @@
 	    RETURN ( self );
 	}
     }
-%}
-.
+%}.
     ^ super from:start to:stop reverseDo:aBlock
 !
 
@@ -691,7 +694,9 @@
      Pass both index and element to the block.
      - reimplemented for speed"
 
-    |home|
+    |home sz "{ Class: SmallInteger }" |
+
+    sz := self size.
 %{
     REGISTER OBJFUNC codeVal;
     REGISTER int index;
@@ -699,8 +704,12 @@
     static struct inlineCache val2 = _ILC2;
     REGISTER OBJ rHome;
 
-    index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
+    index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
+/*
     nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ */
+    nIndex = index + __intVal(sz);
+
     if (__isBlockLike(aBlock)
      && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
      && (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(2))) {
@@ -747,8 +756,7 @@
 			    _InstPtr(self)->i_instvars[index-1]);
 	} 
     }
-%}
-.
+%}.
     ^ self
 !
 
@@ -756,7 +764,9 @@
     "evaluate the argument, aBlock for each element in the collection in reverse order.
      - reimplemented for speed"
 
-    |home|
+    |home sz "{ Class: SmallInteger }" |
+
+    sz := self size.
 %{
     REGISTER OBJFUNC codeVal;
     REGISTER int index;
@@ -765,7 +775,7 @@
     static struct inlineCache val = _ILC1;
 
     endIndex = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
-    nIndex = __arraySize(self);
+    nIndex = endIndex + __intVal(sz);
 
     if (__isBlockLike(aBlock)
      && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
@@ -846,7 +856,7 @@
 		if ((INT)anObject == 0) {
 		    memset(dst, 0, __OBJS2BYTES__(endIndex-index+1));
 		} else {
-#if defined(UNROLL_LOOPS)
+# if defined(UNROLL_LOOPS)
 		    {
 			int i8;
 
@@ -863,7 +873,7 @@
 			    index = i8;
 			}
 		    }
-#endif
+# endif
 		    for (; index <= endIndex; index++) {
 			*dst++ = anObject;
 		    }
@@ -874,8 +884,7 @@
 	    }
 	}
     }
-%}
-.
+%}.
     ^ super from:index1 to:index2 put:anObject
 !
 
@@ -1191,8 +1200,12 @@
      * however, the search is limited to the first 1000
      * elements, since otherwise, we may spend too much time
      * searching for identity if an equal value is found early
+     * (except if searching for nil - there is no need for equal compare ...)
      */
-    if (nIndex > 1000) nIndex = 1000;
+    if (nIndex > 1000) {
+	if (o != nil)
+	    nIndex = 1000;
+    }
 
     o = anObject;
 #if defined(UNROLL_LOOPS)
@@ -1338,4 +1351,4 @@
 !Array class methodsFor:'documentation'!
 
 version
-^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.53 1996-01-05 12:32:59 cg Exp $'! !
+^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.54 1996-02-08 21:19:06 cg Exp $'! !