Array.st
branchjv
changeset 17735 6a5bc05f696a
parent 17734 406b1590afe8
child 17761 b0e5971141bc
--- a/Array.st	Thu Nov 05 14:41:30 2009 +0000
+++ b/Array.st	Wed Dec 02 21:30:55 2009 +0000
@@ -426,6 +426,13 @@
     ^ super asArray
 
     "Modified: 22.4.1996 / 12:42:09 / cg"
+!
+
+asImmutableArray
+    "return a write-protected copy of myself"
+
+    self assert:(ImmutableArray notNil).
+    ^ self copy changeClassTo:ImmutableArray
 ! !
 
 !Array methodsFor:'copying'!
@@ -2090,114 +2097,114 @@
 
     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);
+        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
-		 */
+            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(e)) {
-		    while (index < nIndex) {
-			element = __InstPtr(self)->i_instvars[index++];
-			if (__isNonNilObject(element)) {
-			    if (element == e) {
-				RETURN ( __mkSmallInteger(index - nInsts) );
-			    }
-			    if (__qClass(element) == @global(String)) {
-				if (strcmp(__stringVal(e), __stringVal(element)) == 0) {
-				    RETURN ( __mkSmallInteger(index - nInsts) );
-				}
-			    } else {
-				if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) {
-				    RETURN ( __mkSmallInteger(index - nInsts) );
-				}
-				/*
-				 * send of #= could have lead to a GC - refetch e
-				 */
-				e = anElement;
-			    }
-			}
-		    }
-		    RETURN (__mkSmallInteger(0));
-		}
+                if (__isStringLike(e)) {
+                    while (index < nIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (__isNonNilObject(element)) {
+                            if (element == e) {
+                                RETURN ( __mkSmallInteger(index - nInsts) );
+                            }
+                            if (__qClass(element) == @global(String)) {
+                                if (strcmp(__stringVal(e), __stringVal(element)) == 0) {
+                                    RETURN ( __mkSmallInteger(index - nInsts) );
+                                }
+                            } else {
+                                if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) {
+                                    RETURN ( __mkSmallInteger(index - nInsts) );
+                                }
+                                /*
+                                 * send of #= could have lead to a GC - refetch e
+                                 */
+                                e = anElement;
+                            }
+                        }
+                    }
+                    RETURN (__mkSmallInteger(0));
+                }
 #endif
-		if (__isSmallInteger(e)) {
-		    /* search for a small number */
-		    while (index < nIndex) {
-			element = __InstPtr(self)->i_instvars[index++];
-			if (element == e) {
-			    RETURN ( __mkSmallInteger(index - nInsts) );
-			}
-			if (!__isSmallInteger(element)) {
-			    if ((*eq.ilc_func)(e,
-						@symbol(=), 
-						nil,&eq,
-						element) == true) {
-				RETURN ( __mkSmallInteger(index - nInsts) );
-			    }
-			    /*
-			     * send of #= could have lead to a GC - refetch e
-			     */
-			    e = anElement;
-			}
-		    }
-		    RETURN (__mkSmallInteger(0));
-		}
+                if (__isSmallInteger(e)) {
+                    /* search for a small number */
+                    while (index < nIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (element == e) {
+                            RETURN ( __mkSmallInteger(index - nInsts) );
+                        }
+                        if (!__isSmallInteger(element)) {
+                            if ((*eq.ilc_func)(e,
+                                                @symbol(=), 
+                                                nil,&eq,
+                                                element) == true) {
+                                RETURN ( __mkSmallInteger(index - nInsts) );
+                            }
+                            /*
+                             * send of #= could have lead to a GC - refetch e
+                             */
+                            e = anElement;
+                        }
+                    }
+                    RETURN (__mkSmallInteger(0));
+                }
 
-		while (index < nIndex) {
-		    element = __InstPtr(self)->i_instvars[index++];
-		    if (element != nil) {
-			e = anElement;
+                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 ( __mkSmallInteger(index - nInsts) );
-			}
-		    }
-		}
-	    } else {
-		OBJ slf = self;
+                        if ((element == e) 
+                         || ((*eq.ilc_func)(e,
+                                            @symbol(=), 
+                                            nil,&eq,
+                                            element) == true)) {
+                            RETURN ( __mkSmallInteger(index - nInsts) );
+                        }
+                    }
+                }
+            } else {
+                OBJ slf = self;
 
-		/* 
-		 * search for nil - do an identity-search
-		 */
+                /* 
+                 * search for nil - do an identity-search
+                 */
 #ifdef __UNROLL_LOOPS__
-		{
-		    unsigned int i8;
+                {
+                    unsigned int i8;
 
-		    while ((i8 = index + 8) < nIndex) {
-			if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 1) ); }
-			if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 2) ); }
-			if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 3) ); }
-			if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 4) ); }
-			if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 5) ); }
-			if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 6) ); }
-			if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 7) ); }
-			if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 8) ); }
-			index = i8;
-		    }
-		}
+                    while ((i8 = index + 8) < nIndex) {
+                        if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 1) ); }
+                        if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 2) ); }
+                        if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 3) ); }
+                        if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 4) ); }
+                        if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 5) ); }
+                        if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 6) ); }
+                        if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 7) ); }
+                        if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 8) ); }
+                        index = i8;
+                    }
+                }
 #endif
 
-		while (index < nIndex) {
-		    if (__InstPtr(slf)->i_instvars[index++] == nil) {
-			RETURN ( __mkSmallInteger(index - nInsts) );
-		    }
-		}
-	    }
-	}
-	RETURN (__mkSmallInteger(0));
+                while (index < nIndex) {
+                    if (__InstPtr(slf)->i_instvars[index++] == nil) {
+                        RETURN ( __mkSmallInteger(index - nInsts) );
+                    }
+                }
+            }
+        }
+        RETURN (__mkSmallInteger(0));
     }
 %}.
     ^ super indexOf:anElement startingAt:start
@@ -2218,117 +2225,117 @@
 
     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;
+            }
 
-	    e = anElement;
+            e = anElement;
 
-	    if (e != nil) {
-		/*
-		 * special kludge to search for a string;
-		 * this is so common, that its worth a special case
-		 */
+            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(e)) {
-		    while (index < lastIndex) {
-			element = __InstPtr(self)->i_instvars[index++];
-			if (__isNonNilObject(element)) {
-			    if (element == e) {
-				RETURN ( __mkSmallInteger(index - nInsts) );
-			    }
-			    if (__qClass(element) == @global(String)) {
-				if (strcmp(__stringVal(e), __stringVal(element)) == 0) {
-				    RETURN ( __mkSmallInteger(index - nInsts) );
-				}
-			    } else {
-				if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) {
-				    RETURN ( __mkSmallInteger(index - nInsts) );
-				}
-				/*
-				 * send of #= could have lead to a GC - refetch e
-				 */
-				e = anElement;
-			    }
-			}
-		    }
-		    RETURN (__mkSmallInteger(0));
-		}
+                if (__isStringLike(e)) {
+                    while (index < lastIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (__isNonNilObject(element)) {
+                            if (element == e) {
+                                RETURN ( __mkSmallInteger(index - nInsts) );
+                            }
+                            if (__qClass(element) == @global(String)) {
+                                if (strcmp(__stringVal(e), __stringVal(element)) == 0) {
+                                    RETURN ( __mkSmallInteger(index - nInsts) );
+                                }
+                            } else {
+                                if ((*eq.ilc_func)(e, @symbol(=), nil,&eq, element) == true) {
+                                    RETURN ( __mkSmallInteger(index - nInsts) );
+                                }
+                                /*
+                                 * send of #= could have lead to a GC - refetch e
+                                 */
+                                e = anElement;
+                            }
+                        }
+                    }
+                    RETURN (__mkSmallInteger(0));
+                }
 #endif
-		if (__isSmallInteger(e)) {
-		    /* search for a small number */
-		    while (index < lastIndex) {
-			element = __InstPtr(self)->i_instvars[index++];
-			if (element == e) {
-			    RETURN ( __mkSmallInteger(index - nInsts) );
-			}
-			if (!__isSmallInteger(element)) {
-			    if ((*eq.ilc_func)(e,
-						@symbol(=), 
-						nil,&eq,
-						element) == true) {
-				RETURN ( __mkSmallInteger(index - nInsts) );
-			    }
-			    /*
-			     * send of #= could have lead to a GC - refetch e
-			     */
-			    e = anElement;
-			}
-		    }
-		    RETURN (__mkSmallInteger(0));
-		}
+                if (__isSmallInteger(e)) {
+                    /* search for a small number */
+                    while (index < lastIndex) {
+                        element = __InstPtr(self)->i_instvars[index++];
+                        if (element == e) {
+                            RETURN ( __mkSmallInteger(index - nInsts) );
+                        }
+                        if (!__isSmallInteger(element)) {
+                            if ((*eq.ilc_func)(e,
+                                                @symbol(=), 
+                                                nil,&eq,
+                                                element) == true) {
+                                RETURN ( __mkSmallInteger(index - nInsts) );
+                            }
+                            /*
+                             * send of #= could have lead to a GC - refetch e
+                             */
+                            e = anElement;
+                        }
+                    }
+                    RETURN (__mkSmallInteger(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 ( __mkSmallInteger(index - nInsts) );
-			}
-		    }
-		}
-	    } else {
-		OBJ slf = self;
+                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 ( __mkSmallInteger(index - nInsts) );
+                        }
+                    }
+                }
+            } else {
+                OBJ slf = self;
 
-		/* 
-		 * search for nil - do an identity-search
-		 */
+                /* 
+                 * search for nil - do an identity-search
+                 */
 #ifdef __UNROLL_LOOPS__
-		{
-		    unsigned int i8;
+                {
+                    unsigned int i8;
 
-		    while ((i8 = index + 8) < lastIndex) {
-			if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 1) ); }
-			if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 2) ); }
-			if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 3) ); }
-			if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 4) ); }
-			if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 5) ); }
-			if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 6) ); }
-			if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 7) ); }
-			if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 8) ); }
-			index = i8;
-		    }
-		}
+                    while ((i8 = index + 8) < lastIndex) {
+                        if (__InstPtr(slf)->i_instvars[index] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 1) ); }
+                        if (__InstPtr(slf)->i_instvars[index+1] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 2) ); }
+                        if (__InstPtr(slf)->i_instvars[index+2] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 3) ); }
+                        if (__InstPtr(slf)->i_instvars[index+3] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 4) ); }
+                        if (__InstPtr(slf)->i_instvars[index+4] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 5) ); }
+                        if (__InstPtr(slf)->i_instvars[index+5] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 6) ); }
+                        if (__InstPtr(slf)->i_instvars[index+6] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 7) ); }
+                        if (__InstPtr(slf)->i_instvars[index+7] == nil) { RETURN ( __mkSmallInteger(index - nInsts + 8) ); }
+                        index = i8;
+                    }
+                }
 #endif
-		while (index < lastIndex) {
-		    if (__InstPtr(slf)->i_instvars[index++] == nil) {
-			RETURN ( __mkSmallInteger(index - nInsts) );
-		    }
-		}
-	    }
-	}
-	RETURN (__mkSmallInteger(0));
+                while (index < lastIndex) {
+                    if (__InstPtr(slf)->i_instvars[index++] == nil) {
+                        RETURN ( __mkSmallInteger(index - nInsts) );
+                    }
+                }
+            }
+        }
+        RETURN (__mkSmallInteger(0));
     }
 %}.
     ^ super indexOf:anElement startingAt:start endingAt:stop
@@ -2546,11 +2553,12 @@
 !Array class methodsFor:'documentation'!
 
 version
-    ^ '$Id: Array.st 10477 2009-11-05 14:41:30Z vranyj1 $'
+    ^ '$Id: Array.st 10480 2009-12-02 21:30:55Z vranyj1 $'
 !
 
 version_CVS
-    ^ '$Id: Array.st 10477 2009-11-05 14:41:30Z vranyj1 $'
+    ^ '§Header: /cvs/stx/stx/libbasic/Array.st,v 1.148 2009/11/05 16:25:19 stefan Exp §'
 ! !
 
 
+