checkin from browser
authorClaus Gittinger <cg@exept.de>
Sun, 02 Nov 1997 20:11:49 +0100
changeset 3088 8b7011bef899
parent 3087 609b8f05a250
child 3089 0823aa17ac4d
checkin from browser
Array.st
--- a/Array.st	Sun Nov 02 19:37:48 1997 +0100
+++ b/Array.st	Sun Nov 02 20:11:49 1997 +0100
@@ -1625,7 +1625,7 @@
     "Modified: 22.4.1996 / 12:41:46 / cg"
 ! !
 
-!Array methodsFor:'testing'!
+!Array methodsFor:'searching'!
 
 identityIndexOf:anElement or:alternative 
     "search the array for anElement or alternative; 
@@ -1875,129 +1875,6 @@
 
 !
 
-includes:anObject
-    "return true, if the argument, anObject is contained in the array
-     - reimplemented for speed"
-
-    |element|
-
-%{  /* NOCONTEXT */
-
-    /* 
-     * first, do a quick check using ==
-     * this does not need a context or message send.
-     * In many cases this will already find a match.
-     */
-    REGISTER int index;
-    REGISTER OBJ o;
-    unsigned int nIndex;
-    static struct inlineCache eq = _ILC1;
-
-    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
-    index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
-
-    /*
-     * however, the search is limited to the first 500
-     * 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 > 500) {
-	if (o != nil)
-	    nIndex = 500;
-    }
-
-    o = anObject;
-
-# ifdef memsrch4
-    if (index < nIndex) {
-	OBJ *p;
-
-	p = memsrch4(&(__InstPtr(self)->i_instvars[index]), (INT)o, (nIndex - index));
-	if (p) {
-	    RETURN ( true );
-	}
-    }
-
-# else
-    /*
-     * dont argue those gotos below - they speed up that thing by 30%
-     * its better to exit the loops below with a goto,
-     * since the generated code will then be:
-     *   compare
-     *   branch-on-equal found
-     *
-     * otherwise, we get:
-     *   compare
-     *   branch-on-not-equal skipLabel
-     *   move-to-return-register true
-     *   goto return-label
-     * skipLabel
-     *
-     * therefore, WITH the so-much-blamed goto, we only branch
-     * when found; without the goto, we branch always.
-     * Pipelined CPUs do usually not like taken branches.
-     * also, all branches are forward, which are usually predicted
-     * as not taken.
-     */
-#  if defined(UNROLL_LOOPS)
-    {
-	unsigned int i8;
-	REGISTER OBJ slf = self;
-
-	while ((i8 = index + 8) < nIndex) {
-	    if (__InstPtr(slf)->i_instvars[index] == o) goto found;
-	    if (__InstPtr(slf)->i_instvars[index+1] == o) goto found;
-	    if (__InstPtr(slf)->i_instvars[index+2] == o) goto found;
-	    if (__InstPtr(slf)->i_instvars[index+3] == o) goto found;
-	    if (__InstPtr(slf)->i_instvars[index+4] == o) goto found;
-	    if (__InstPtr(slf)->i_instvars[index+5] == o) goto found;
-	    if (__InstPtr(slf)->i_instvars[index+6] == o) goto found;
-	    if (__InstPtr(slf)->i_instvars[index+7] == o) goto found;
-	    index = i8;
-	}
-    }
-#  endif /* UNROLL_LOOPS */
-
-    while (index < nIndex) {
-	if (__InstPtr(self)->i_instvars[index++] == o) goto found;
-    }
-    if (0) {
-	found:
-	    RETURN (true);
-    }
-
-# endif /* no memsrch */
-
-    if (o == nil) {
-	RETURN ( false );
-    }
-
-    /* 
-     * then do a slow(er) check using =
-     */
-
-    /* 
-     * sorry: cannot access the stuff from above ...
-     */
-    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
-    index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
-
-    while (index < nIndex) {
-	element = __InstPtr(self)->i_instvars[index++];
-	if (element != nil) {
-	    if ((*eq.ilc_func)(anObject,
-			       @symbol(=),
-			       nil,&eq,
-			       element)==true) {
-		RETURN ( true );
-	    }
-	}
-    }
-%}.
-    ^ false
-!
-
 indexOf:anElement startingAt:start
     "search the array for anElement; return index if found, 0 otherwise
      - reimplemented for speed"
@@ -2207,8 +2084,133 @@
     ^ super indexOf:anElement startingAt:start endingAt:stop
 ! !
 
+!Array methodsFor:'testing'!
+
+includes:anObject
+    "return true, if the argument, anObject is contained in the array
+     - reimplemented for speed"
+
+    |element|
+
+%{  /* NOCONTEXT */
+
+    /* 
+     * first, do a quick check using ==
+     * this does not need a context or message send.
+     * In many cases this will already find a match.
+     */
+    REGISTER int index;
+    REGISTER OBJ o;
+    unsigned int nIndex;
+    static struct inlineCache eq = _ILC1;
+
+    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+    index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
+
+    /*
+     * however, the search is limited to the first 500
+     * 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 > 500) {
+	if (o != nil)
+	    nIndex = 500;
+    }
+
+    o = anObject;
+
+# ifdef memsrch4
+    if (index < nIndex) {
+	OBJ *p;
+
+	p = memsrch4(&(__InstPtr(self)->i_instvars[index]), (INT)o, (nIndex - index));
+	if (p) {
+	    RETURN ( true );
+	}
+    }
+
+# else
+    /*
+     * dont argue those gotos below - they speed up that thing by 30%
+     * its better to exit the loops below with a goto,
+     * since the generated code will then be:
+     *   compare
+     *   branch-on-equal found
+     *
+     * otherwise, we get:
+     *   compare
+     *   branch-on-not-equal skipLabel
+     *   move-to-return-register true
+     *   goto return-label
+     * skipLabel
+     *
+     * therefore, WITH the so-much-blamed goto, we only branch
+     * when found; without the goto, we branch always.
+     * Pipelined CPUs do usually not like taken branches.
+     * also, all branches are forward, which are usually predicted
+     * as not taken.
+     */
+#  if defined(UNROLL_LOOPS)
+    {
+	unsigned int i8;
+	REGISTER OBJ slf = self;
+
+	while ((i8 = index + 8) < nIndex) {
+	    if (__InstPtr(slf)->i_instvars[index] == o) goto found;
+	    if (__InstPtr(slf)->i_instvars[index+1] == o) goto found;
+	    if (__InstPtr(slf)->i_instvars[index+2] == o) goto found;
+	    if (__InstPtr(slf)->i_instvars[index+3] == o) goto found;
+	    if (__InstPtr(slf)->i_instvars[index+4] == o) goto found;
+	    if (__InstPtr(slf)->i_instvars[index+5] == o) goto found;
+	    if (__InstPtr(slf)->i_instvars[index+6] == o) goto found;
+	    if (__InstPtr(slf)->i_instvars[index+7] == o) goto found;
+	    index = i8;
+	}
+    }
+#  endif /* UNROLL_LOOPS */
+
+    while (index < nIndex) {
+	if (__InstPtr(self)->i_instvars[index++] == o) goto found;
+    }
+    if (0) {
+	found:
+	    RETURN (true);
+    }
+
+# endif /* no memsrch */
+
+    if (o == nil) {
+	RETURN ( false );
+    }
+
+    /* 
+     * then do a slow(er) check using =
+     */
+
+    /* 
+     * sorry: cannot access the stuff from above ...
+     */
+    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+    index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
+
+    while (index < nIndex) {
+	element = __InstPtr(self)->i_instvars[index++];
+	if (element != nil) {
+	    if ((*eq.ilc_func)(anObject,
+			       @symbol(=),
+			       nil,&eq,
+			       element)==true) {
+		RETURN ( true );
+	    }
+	}
+    }
+%}.
+    ^ false
+! !
+
 !Array class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.103 1997-10-16 10:35:03 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.104 1997-11-02 19:11:49 cg Exp $'
 ! !