Array.st
changeset 4130 662554f2a37c
parent 4122 7e3b6b267c06
child 4305 e71100d13b67
--- a/Array.st	Thu Apr 29 16:01:40 1999 +0200
+++ b/Array.st	Fri Apr 30 00:38:23 1999 +0200
@@ -1995,85 +1995,118 @@
     REGISTER int index;
     unsigned int nIndex, nInsts;
     static struct inlineCache eq = _ILC1;
-    OBJ myClass;
+    OBJ myClass, e;
 
     myClass = __qClass(self);
     if ( __isSmallInteger(start) ) {
-	index = __intVal(start) - 1;
-	if (index >= 0) {
-	    nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars);
-	    index += nInsts;
-	    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
-	    if (anElement != nil) {
-		/*
-		 * special kludge to search for a string;
-		 * this is so common, that its worth a special case
-		 */
+        index = __intVal(start) - 1;
+        if (index >= 0) {
+            nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars);
+            index += nInsts;
+            nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+
+            e = anElement;
+            if (e != nil) {
+                /*
+                 * special kludge to search for a string;
+                 * this is so common, that its worth a special case
+                 */
 #define SPECIAL_STRING_OPT
 #ifdef SPECIAL_STRING_OPT
-		if (__isString(anElement)) {
-		    while (index < nIndex) {
-			element = __InstPtr(self)->i_instvars[index++];
-			if (__isNonNilObject(element)) {
-			    if (element == anElement) {
-				RETURN ( __MKSMALLINT(index - nInsts) );
-			    }
-			    if (__qClass(element) == @global(String)) {
-				if (strcmp(__stringVal(anElement), __stringVal(element)) == 0) {
-				    RETURN ( __MKSMALLINT(index - nInsts) );
-				}
-			    } else {
-				if ((*eq.ilc_func)(anElement, @symbol(=), nil,&eq, element) == true) {
-				    RETURN ( __MKSMALLINT(index - nInsts) );
-				}
-			    }
-			}
-		    }
-		    RETURN (__MKSMALLINT(0));
-		}
+                if (__isString(e)) {
+                    while (index < nIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (__isNonNilObject(element)) {
+                            if (element == e) {
+                                RETURN ( __MKSMALLINT(index - nInsts) );
+                            }
+                            if (__qClass(element) == @global(String)) {
+                                if (strcmp(__stringVal(e), __stringVal(element)) == 0) {
+                                    RETURN ( __MKSMALLINT(index - nInsts) );
+                                }
+                            } else {
+                                if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) {
+                                    RETURN ( __MKSMALLINT(index - nInsts) );
+                                }
+                                /*
+                                 * send of #= could have lead to a GC - refetch e
+                                 */
+                                e = anElement;
+                            }
+                        }
+                    }
+                    RETURN (__MKSMALLINT(0));
+                }
 #endif
-		while (index < nIndex) {
-		    element = __InstPtr(self)->i_instvars[index++];
-		    if (element != nil) {
-			if ((element == anElement) 
-			 || ((*eq.ilc_func)(anElement,
-					    @symbol(=), 
-					    nil,&eq,
-					    element) == true)) {
-			    RETURN ( __MKSMALLINT(index - nInsts) );
-			}
-		    }
-		}
-	    } else {
-		/* 
-		 * search for nil - do an identity-search
-		 */
+                if (__isSmallInteger(e)) {
+                    /* search for a small number */
+                    while (index < nIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (element == e) {
+                            RETURN ( __MKSMALLINT(index - nInsts) );
+                        }
+                        if (!__isSmallInteger(element)) {
+                            if ((*eq.ilc_func)(e,
+                                                @symbol(=), 
+                                                nil,&eq,
+                                                element) == true) {
+                                RETURN ( __MKSMALLINT(index - nInsts) );
+                            }
+                            /*
+                             * send of #= could have lead to a GC - refetch e
+                             */
+                            e = anElement;
+                        }
+                    }
+                    RETURN (__MKSMALLINT(0));
+                }
+
+                while (index < nIndex) {
+                    element = __InstPtr(self)->i_instvars[index++];
+                    if (element != nil) {
+                        e = anElement;
+
+                        if ((element == e) 
+                         || ((*eq.ilc_func)(e,
+                                            @symbol(=), 
+                                            nil,&eq,
+                                            element) == true)) {
+                            RETURN ( __MKSMALLINT(index - nInsts) );
+                        }
+                    }
+                }
+            } else {
+                OBJ slf = self;
+
+                /* 
+                 * search for nil - do an identity-search
+                 */
 #if defined(UNROLL_LOOPS)
-		{
-		    unsigned int i8;
+                {
+                    unsigned int i8;
 
-		    while ((i8 = index + 8) < nIndex) {
-			if (__InstPtr(self)->i_instvars[index] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 1) ); }
-			if (__InstPtr(self)->i_instvars[index+1] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 2) ); }
-			if (__InstPtr(self)->i_instvars[index+2] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 3) ); }
-			if (__InstPtr(self)->i_instvars[index+3] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 4) ); }
-			if (__InstPtr(self)->i_instvars[index+4] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 5) ); }
-			if (__InstPtr(self)->i_instvars[index+5] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 6) ); }
-			if (__InstPtr(self)->i_instvars[index+6] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 7) ); }
-			if (__InstPtr(self)->i_instvars[index+7] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 8) ); }
-			index = i8;
-		    }
-		}
+                    while ((i8 = index + 8) < nIndex) {
+                        if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 1) ); }
+                        if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 2) ); }
+                        if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 3) ); }
+                        if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 4) ); }
+                        if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 5) ); }
+                        if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 6) ); }
+                        if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 7) ); }
+                        if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 8) ); }
+                        index = i8;
+                    }
+                }
 #endif
 
-		while (index < nIndex) {
-		    if (__InstPtr(self)->i_instvars[index++] == nil) {
-			RETURN ( __MKSMALLINT(index - nInsts) );
-		    }
-		}
-	    }
-	}
-	RETURN (__MKSMALLINT(0));
+                while (index < nIndex) {
+                    if (__InstPtr(slf)->i_instvars[index++] == nil) {
+                        RETURN ( __MKSMALLINT(index - nInsts) );
+                    }
+                }
+            }
+        }
+        RETURN (__MKSMALLINT(0));
     }
 %}.
     ^ super indexOf:anElement startingAt:start
@@ -2089,107 +2122,121 @@
     REGISTER int index;
     unsigned int lastIndex, nIndex, nInsts;
     static struct inlineCache eq = _ILC1;
-    OBJ myClass;
+    OBJ myClass, e;
 
     myClass = __qClass(self);
     if ( __bothSmallInteger(start, stop) ) {
-	index = __intVal(start) - 1;
-	if (index >= 0) {
-	    nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars);
-	    index += nInsts;
-	    lastIndex = nInsts + __intVal(stop);
-	    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
-	    if (nIndex < lastIndex) {
-		lastIndex = nIndex;
-	    }
+        index = __intVal(start) - 1;
+        if (index >= 0) {
+            nInsts = __intVal(__ClassInstPtr(myClass)->c_ninstvars);
+            index += nInsts;
+            lastIndex = nInsts + __intVal(stop);
+            nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+            if (nIndex < lastIndex) {
+                lastIndex = nIndex;
+            }
 
-	    if (anElement != nil) {
-		/*
-		 * special kludge to search for a string;
-		 * this is so common, that its worth a special case
-		 */
+            e = anElement;
+
+            if (e != nil) {
+                /*
+                 * special kludge to search for a string;
+                 * this is so common, that its worth a special case
+                 */
+#define SPECIAL_STRING_OPT
 #ifdef SPECIAL_STRING_OPT
-		if (__isString(anElement)) {
-		    while (index < lastIndex) {
-			element = __InstPtr(self)->i_instvars[index++];
-			if (__isNonNilObject(element)) {
-			    if (element == anElement) {
-				RETURN ( __MKSMALLINT(index - nInsts) );
-			    }
-			    if (__qClass(element) == @global(String)) {
-				if (strcmp(__stringVal(anElement), __stringVal(element)) == 0) {
-				    RETURN ( __MKSMALLINT(index - nInsts) );
-				}
-			    } else {
-				if ((*eq.ilc_func)(anElement, @symbol(=), nil,&eq, element) == true) {
-				    RETURN ( __MKSMALLINT(index - nInsts) );
-				}
-			    }
-			}
-		    }
-		    RETURN (__MKSMALLINT(0));
-		}
+                if (__isString(e)) {
+                    while (index < lastIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (__isNonNilObject(e)) {
+                            if (element == e) {
+                                RETURN ( __MKSMALLINT(index - nInsts) );
+                            }
+                            if (__qClass(element) == @global(String)) {
+                                if (strcmp(__stringVal(e), __stringVal(element)) == 0) {
+                                    RETURN ( __MKSMALLINT(index - nInsts) );
+                                }
+                            } else {
+                                if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) {
+                                    RETURN ( __MKSMALLINT(index - nInsts) );
+                                }
+                                /*
+                                 * send of #= could have lead to a GC - refetch e
+                                 */
+                                e = anElement;
+                            }
+                        }
+                    }
+                    RETURN (__MKSMALLINT(0));
+                }
 #endif
-		while (index < lastIndex) {
-		    element = __InstPtr(self)->i_instvars[index++];
-		    if (element != nil) {
-			if ((element == anElement) 
-			 || ((*eq.ilc_func)(anElement,
-					    @symbol(=), 
-					    nil,&eq,
-					    element) == true)) {
-			    RETURN ( __MKSMALLINT(index - nInsts) );
-			}
-		    }
-		}
-	    } else {
-		if (__isSmallInteger(anElement)) {
-		    /* search for a small number */
-		    while (index < lastIndex) {
-			element = __InstPtr(self)->i_instvars[index++];
-			if (element == anElement) {
-			    RETURN ( __MKSMALLINT(index - nInsts) );
-			}
-			if (!__isSmallInteger(element)) {
-			    if ((*eq.ilc_func)(anElement,
-						@symbol(=), 
-						nil,&eq,
-						element) == true) {
-				RETURN ( __MKSMALLINT(index - nInsts) );
-			    }
-			}
-		    }
-		} else {
-		    /* 
-		     * search for nil - do an identity-search
-		     */
+                if (__isSmallInteger(e)) {
+                    /* search for a small number */
+                    while (index < lastIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (element == e) {
+                            RETURN ( __MKSMALLINT(index - nInsts) );
+                        }
+                        if (!__isSmallInteger(element)) {
+                            if ((*eq.ilc_func)(e,
+                                                @symbol(=), 
+                                                nil,&eq,
+                                                element) == true) {
+                                RETURN ( __MKSMALLINT(index - nInsts) );
+                            }
+                            /*
+                             * send of #= could have lead to a GC - refetch e
+                             */
+                            e = anElement;
+                        }
+                    }
+                    RETURN (__MKSMALLINT(0));
+                }
+
+                while (index < lastIndex) {
+                    element = __InstPtr(self)->i_instvars[index++];
+                    if (element != nil) {
+                        e = anElement;
+                        if ((element == e) 
+                         || ((*eq.ilc_func)(e,
+                                            @symbol(=), 
+                                            nil,&eq,
+                                            element) == true)) {
+                            RETURN ( __MKSMALLINT(index - nInsts) );
+                        }
+                    }
+                }
+            } else {
+                OBJ slf = self;
+
+                /* 
+                 * search for nil - do an identity-search
+                 */
 #if defined(UNROLL_LOOPS)
-		    {
-			unsigned int i8;
+                {
+                    unsigned int i8;
 
-			while ((i8 = index + 8) < lastIndex) {
-			    if (__InstPtr(self)->i_instvars[index] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 1) ); }
-			    if (__InstPtr(self)->i_instvars[index+1] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 2) ); }
-			    if (__InstPtr(self)->i_instvars[index+2] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 3) ); }
-			    if (__InstPtr(self)->i_instvars[index+3] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 4) ); }
-			    if (__InstPtr(self)->i_instvars[index+4] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 5) ); }
-			    if (__InstPtr(self)->i_instvars[index+5] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 6) ); }
-			    if (__InstPtr(self)->i_instvars[index+6] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 7) ); }
-			    if (__InstPtr(self)->i_instvars[index+7] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 8) ); }
-			    index = i8;
-			}
-		    }
+                    while ((i8 = index + 8) < lastIndex) {
+                        if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 1) ); }
+                        if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 2) ); }
+                        if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 3) ); }
+                        if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 4) ); }
+                        if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 5) ); }
+                        if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 6) ); }
+                        if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 7) ); }
+                        if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __MKSMALLINT(index - nInsts + 8) ); }
+                        index = i8;
+                    }
+                }
 #endif
-
-		    while (index < lastIndex) {
-			if (__InstPtr(self)->i_instvars[index++] == nil) {
-			    RETURN ( __MKSMALLINT(index - nInsts) );
-			}
-		    }
-		}
-	    }
-	}
-	RETURN (__MKSMALLINT(0));
+                while (index < lastIndex) {
+                    if (__InstPtr(slf)->i_instvars[index++] == nil) {
+                        RETURN ( __MKSMALLINT(index - nInsts) );
+                    }
+                }
+            }
+        }
+        RETURN (__MKSMALLINT(0));
     }
 %}.
     ^ super indexOf:anElement startingAt:start endingAt:stop
@@ -2323,5 +2370,5 @@
 !Array class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.113 1999-04-25 12:40:20 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.114 1999-04-29 22:38:23 cg Exp $'
 ! !