Array.st
changeset 302 1f76060d58a4
parent 293 31df3850e98c
child 325 46bca6125b93
equal deleted inserted replaced
301:35e40a6fc72b 302:1f76060d58a4
    19 
    19 
    20 Array comment:'
    20 Array comment:'
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    22 	      All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libbasic/Array.st,v 1.21 1995-03-06 19:14:47 claus Exp $
    24 $Header: /cvs/stx/stx/libbasic/Array.st,v 1.22 1995-03-08 23:36:43 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !Array class methodsFor:'documentation'!
    27 !Array class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libbasic/Array.st,v 1.21 1995-03-06 19:14:47 claus Exp $
    45 $Header: /cvs/stx/stx/libbasic/Array.st,v 1.22 1995-03-08 23:36:43 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
   385     int repStopIndex;
   385     int repStopIndex;
   386     REGISTER int repStartIndex;
   386     REGISTER int repStartIndex;
   387     REGISTER OBJ t;
   387     REGISTER OBJ t;
   388     REGISTER int count;
   388     REGISTER int count;
   389 
   389 
   390     if ((_qClass(self) == Array)
   390     
   391      && (_Class(aCollection) == Array)
   391     if ((_ClassInstPtr(_qClass(self))->c_ninstvars == _MKSMALLINT(0))
       
   392      && (((t = _Class(aCollection)) == Array) || (t == _qClass(self)))
   392      && __bothSmallInteger(start, stop)
   393      && __bothSmallInteger(start, stop)
   393      && __isSmallInteger(repStart)) {
   394      && __isSmallInteger(repStart)) {
   394 	startIndex = _intVal(start) - 1;
   395 	startIndex = _intVal(start) - 1;
   395 	if (startIndex >= 0) {
   396 	if (startIndex >= 0) {
   396 	    nIndex = __BYTES2OBJS__(_qSize(self) - OHDR_SIZE);
   397 	    nIndex = __BYTES2OBJS__(_qSize(self) - OHDR_SIZE);
   429 				*dst++ = *src++;
   430 				*dst++ = *src++;
   430 			    }
   431 			    }
   431 # endif
   432 # endif
   432 #endif
   433 #endif
   433 			} else {
   434 			} else {
   434     			    REGISTER int spc;
   435 			    REGISTER int spc;
   435 
   436 
   436 			    spc = _qSpace(self);
   437 			    spc = _qSpace(self);
   437 			    while (count-- > 0) {
   438 			    while (count-- > 0) {
   438 				t = *src++;
   439 				t = *src++;
   439 				*dst++ = t;
   440 				*dst++ = t;
   478 
   479 
   479 %{  /* NOCONTEXT */
   480 %{  /* NOCONTEXT */
   480 
   481 
   481     /* 
   482     /* 
   482      * first, do a quick check using ==
   483      * first, do a quick check using ==
   483      * this does not need a context or method send.
   484      * this does not need a context or message send.
   484      * in many cases this will already find a match
   485      * in many cases this will already find a match
   485      */
   486      */
   486     REGISTER int index;
   487     REGISTER int index;
   487     REGISTER OBJ o;
   488     REGISTER OBJ o;
   488     unsigned int nIndex;
   489     unsigned int nIndex;
   644 
   645 
   645 do:aBlock
   646 do:aBlock
   646     "evaluate the argument, aBlock for each element in the collection.
   647     "evaluate the argument, aBlock for each element in the collection.
   647      - reimplemented for speed"
   648      - reimplemented for speed"
   648 
   649 
   649     |home element|
   650     |home|
   650 %{
   651 %{
   651     REGISTER OBJFUNC codeVal;
   652     REGISTER OBJFUNC codeVal;
   652     REGISTER int index;
   653     REGISTER int index;
   653     unsigned int nIndex;
   654     unsigned int nIndex;
   654     extern OBJ Block;
   655     extern OBJ Block;
   767 
   768 
   768 reverseDo:aBlock
   769 reverseDo:aBlock
   769     "evaluate the argument, aBlock for each element in the collection in reverse order.
   770     "evaluate the argument, aBlock for each element in the collection in reverse order.
   770      - reimplemented for speed"
   771      - reimplemented for speed"
   771 
   772 
   772     |home element|
   773     |home|
   773 %{
   774 %{
   774     REGISTER OBJFUNC codeVal;
   775     REGISTER OBJFUNC codeVal;
   775     REGISTER int index;
   776     REGISTER int index;
   776     unsigned int nIndex;
   777     unsigned int nIndex;
   777     int endIndex;
   778     int endIndex;
   812 from:start to:stop do:aBlock
   813 from:start to:stop do:aBlock
   813     "evaluate the argument, aBlock for the elements starting at index start
   814     "evaluate the argument, aBlock for the elements starting at index start
   814      up to (and including) stop in the collection.
   815      up to (and including) stop in the collection.
   815      - reimplemented for speed"
   816      - reimplemented for speed"
   816 
   817 
   817     |home element|
   818     |home|
   818 %{
   819 %{
   819     REGISTER OBJFUNC codeVal;
   820     REGISTER OBJFUNC codeVal;
   820     REGISTER int index;
   821     REGISTER int index;
   821     REGISTER OBJ rHome;
   822     REGISTER OBJ rHome;
   822     int nIndex, nInsts;
   823     int nIndex, nInsts;
   861 		    }
   862 		    }
   862 #endif
   863 #endif
   863 		} else {
   864 		} else {
   864 		    for (index=indexLow; index <= indexHigh; index++) {
   865 		    for (index=indexLow; index <= indexHigh; index++) {
   865 			if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
   866 			if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
   866 			element = _InstPtr(self)->i_instvars[index];
       
   867 			(*val.ilc_func) (aBlock, 
   867 			(*val.ilc_func) (aBlock, 
   868 					 @symbol(value:), 
   868 					 @symbol(value:), 
   869 					 CON_COMMA  nil, &val, 
   869 					 CON_COMMA  nil, &val, 
   870 					 element);
   870 					 _InstPtr(self)->i_instvars[index]);
   871 		    } 
   871 		    } 
   872 		}
   872 		}
   873 	    }
   873 	    }
   874 	    RETURN ( self );
   874 	    RETURN ( self );
   875 	}
   875 	}
   882 from:start to:stop reverseDo:aBlock
   882 from:start to:stop reverseDo:aBlock
   883     "evaluate the argument, aBlock for the elements starting at index start
   883     "evaluate the argument, aBlock for the elements starting at index start
   884      up to (and including) stop in the collection. Step in reverse order.
   884      up to (and including) stop in the collection. Step in reverse order.
   885      - reimplemented for speed"
   885      - reimplemented for speed"
   886 
   886 
   887     |home element|
   887     |home|
   888 %{
   888 %{
   889     REGISTER OBJFUNC codeVal;
   889     REGISTER OBJFUNC codeVal;
   890     REGISTER int index;
   890     REGISTER int index;
   891     REGISTER OBJ rHome;
   891     REGISTER OBJ rHome;
   892     int nIndex, nInsts;
   892     int nIndex, nInsts;
   931 		    }
   931 		    }
   932 #endif
   932 #endif
   933 		} else {
   933 		} else {
   934 		    for (index=indexHigh; index >= indexLow; index--) {
   934 		    for (index=indexHigh; index >= indexLow; index--) {
   935 			if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
   935 			if (InterruptPending != nil) interruptL(__LINE__ COMMA_CON);
   936 			element = _InstPtr(self)->i_instvars[index];
       
   937 			(*val.ilc_func) (aBlock, 
   936 			(*val.ilc_func) (aBlock, 
   938 					 @symbol(value:), 
   937 					 @symbol(value:), 
   939 					 CON_COMMA nil, &val, 
   938 					 CON_COMMA nil, &val, 
   940 					 element);
   939 					 _InstPtr(self)->i_instvars[index]);
   941 		    } 
   940 		    } 
   942 		}
   941 		}
   943 	    }
   942 	    }
   944 	    RETURN ( self );
   943 	    RETURN ( self );
   945 	}
   944 	}
   950 !
   949 !
   951 
   950 
   952 nonNilElementsDo:aBlock
   951 nonNilElementsDo:aBlock
   953     "evaluate the argument, aBlock for each non-nil element"
   952     "evaluate the argument, aBlock for each non-nil element"
   954 
   953 
   955     |home element|
   954     |home|
   956 %{
   955 %{
   957     REGISTER OBJFUNC codeVal;
   956     REGISTER OBJFUNC codeVal;
   958     REGISTER int index;
   957     REGISTER int index;
   959     int nIndex;
   958     int nIndex;
   960     extern OBJ Block;
   959     extern OBJ Block;
   961     static struct inlineCache val = _ILC1;
   960     static struct inlineCache val = _ILC1;
       
   961     REGISTER OBJ rHome;
       
   962     REGISTER OBJ element;
   962 
   963 
   963     index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
   964     index = _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars);
   964     nIndex = __BYTES2OBJS__(_qSize(self) - OHDR_SIZE);
   965     nIndex = __BYTES2OBJS__(_qSize(self) - OHDR_SIZE);
   965     if (__isBlockLike(aBlock)
   966     if (__isBlockLike(aBlock)
   966      && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
   967      && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
   973 	    if (element != nil)
   974 	    if (element != nil)
   974 		(*codeVal)(aBlock, CON_COMMA  element);
   975 		(*codeVal)(aBlock, CON_COMMA  element);
   975 	} 
   976 	} 
   976 #else
   977 #else
   977 	home = _BlockInstPtr(aBlock)->b_home;
   978 	home = _BlockInstPtr(aBlock)->b_home;
   978 	for (; index < nIndex; index++) {
   979         rHome = home;
   979 	    if (InterruptPending != nil) interrupt(CONARG);
   980         if ((rHome == nil) || (_qSpace(rHome) >= STACKSPACE)) {
   980 
   981             /*
   981 	    element = _InstPtr(self)->i_instvars[index];
   982              * home will not move - keep in in a register
   982 	    if (element != nil)
   983              */
   983 		(*codeVal)(home, CON_COMMA  element);
   984 	    for (; index < nIndex; index++) {
       
   985 	        if (InterruptPending != nil) interrupt(CONARG);
       
   986 
       
   987 	        element = _InstPtr(self)->i_instvars[index];
       
   988 	        if (element != nil)
       
   989 		    (*codeVal)(home, CON_COMMA  element);
       
   990 	    } 
       
   991 	} else {
       
   992 	    for (; index < nIndex; index++) {
       
   993 	        if (InterruptPending != nil) interrupt(CONARG);
       
   994 
       
   995 	        element = _InstPtr(self)->i_instvars[index];
       
   996 	        if (element != nil)
       
   997 		    (*codeVal)(home, CON_COMMA  element);
       
   998 	    }
   984 	} 
   999 	} 
   985 #endif
  1000 #endif
   986     } else {
  1001     } else {
   987 	for (; index < nIndex; index++) {
  1002 	for (; index < nIndex; index++) {
   988 	    if (InterruptPending != nil) interrupt(CONARG);
  1003 	    if (InterruptPending != nil) interrupt(CONARG);