Array.st
changeset 18654 12e555d89149
parent 18579 3dedfc433f6a
child 18678 a9b30d72dff9
child 18937 5771812c3f5a
equal deleted inserted replaced
18653:51b75b45b563 18654:12e555d89149
   325 
   325 
   326     if (__isSmallInteger(index)) {
   326     if (__isSmallInteger(index)) {
   327 	indx = __intVal(index) - 1;
   327 	indx = __intVal(index) - 1;
   328 	slf = self;
   328 	slf = self;
   329 
   329 
       
   330 	cls = __qClass(slf);
   330 	nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE);
   331 	nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE);
   331 	if ((cls = __qClass(slf)) != Array) {
   332 	if (cls == Array) {
   332 	    if (indx < 0) goto badIndex;
   333 fetch:
       
   334 	    if ((unsigned INT)indx < (unsigned INT)nIndex) {
       
   335 		RETURN ( __InstPtr(slf)->i_instvars[indx] );
       
   336 	    }
       
   337 	    goto badIndex;
       
   338 	}
       
   339 	if (indx >= 0) {
   333 	    indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
   340 	    indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
   334 	}
   341 	    goto fetch;
   335 	if ((unsigned INT)indx < (unsigned INT)nIndex) {
       
   336 	    RETURN ( __InstPtr(slf)->i_instvars[indx] );
       
   337 	}
   342 	}
   338     }
   343     }
   339 badIndex: ;
   344 badIndex: ;
   340 #endif /* not SCHTEAM */
   345 #endif /* not SCHTEAM */
   341 %}.
   346 %}.
   366 
   371 
   367     if (__isSmallInteger(index)) {
   372     if (__isSmallInteger(index)) {
   368 	indx = __intVal(index) - 1;
   373 	indx = __intVal(index) - 1;
   369 	slf = self;
   374 	slf = self;
   370 
   375 
       
   376 	cls = __qClass(slf);
   371 	nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE);
   377 	nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE);
   372 	if ((cls = __qClass(slf)) != Array) {
   378 	if (cls == Array) {
   373 	    if (indx < 0) goto badIndex;
   379 store:
       
   380 	    if ((unsigned INT)indx < (unsigned INT)nIndex) {
       
   381 		__InstPtr(slf)->i_instvars[indx] = anObject;
       
   382 		__STORE(slf, anObject);
       
   383 		RETURN ( anObject );
       
   384 	    }
       
   385 	    goto badIndex;
       
   386 	}
       
   387 	if (indx >= 0) {
   374 	    indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
   388 	    indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
   375 	}
   389 	    goto store;
   376 	if ((unsigned INT)indx < (unsigned INT)nIndex) {
       
   377 	    __InstPtr(slf)->i_instvars[indx] = anObject;
       
   378 	    __STORE(slf, anObject);
       
   379 	    RETURN ( anObject );
       
   380 	}
   390 	}
   381     }
   391     }
   382 badIndex: ;
   392 badIndex: ;
   383 #endif /* not SCHTEAM */
   393 #endif /* not SCHTEAM */
   384 %}.
   394 %}.
  1617     REGISTER OBJ t;
  1627     REGISTER OBJ t;
  1618     REGISTER INT count;
  1628     REGISTER INT count;
  1619     OBJ myClass;
  1629     OBJ myClass;
  1620 
  1630 
  1621     if (
  1631     if (
  1622         (__ClassInstPtr((myClass = __qClass(self)))->c_ninstvars == __mkSmallInteger(0))
  1632 	(__ClassInstPtr((myClass = __qClass(self)))->c_ninstvars == __mkSmallInteger(0))
  1623      && __isNonNilObject(aCollection)
  1633      && __isNonNilObject(aCollection)
  1624      && (((t = __qClass(aCollection)) == Array) || (t == myClass))
  1634      && (((t = __qClass(aCollection)) == Array) || (t == myClass))
  1625      && __bothSmallInteger(start, stop)
  1635      && __bothSmallInteger(start, stop)
  1626      && __isSmallInteger(repStart)
  1636      && __isSmallInteger(repStart)
  1627     ) {
  1637     ) {
  1628         startIndex = __intVal(start) - 1;
  1638 	startIndex = __intVal(start) - 1;
  1629         if (startIndex >= 0) {
  1639 	if (startIndex >= 0) {
  1630             nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
  1640 	    nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
  1631             stopIndex = __intVal(stop) - 1;
  1641 	    stopIndex = __intVal(stop) - 1;
  1632             count = stopIndex - startIndex + 1;
  1642 	    count = stopIndex - startIndex + 1;
  1633 
  1643 
  1634             if ((count > 0) && (stopIndex < nIndex)) {
  1644 	    if ((count > 0) && (stopIndex < nIndex)) {
  1635                 repStartIndex = __intVal(repStart) - 1;
  1645 		repStartIndex = __intVal(repStart) - 1;
  1636                 if (repStartIndex >= 0) {
  1646 		if (repStartIndex >= 0) {
  1637                     repNIndex = __BYTES2OBJS__(__qSize(aCollection)-OHDR_SIZE);
  1647 		    repNIndex = __BYTES2OBJS__(__qSize(aCollection)-OHDR_SIZE);
  1638                     repStopIndex = repStartIndex + (stopIndex - startIndex);
  1648 		    repStopIndex = repStartIndex + (stopIndex - startIndex);
  1639                     if (repStopIndex < repNIndex) {
  1649 		    if (repStopIndex < repNIndex) {
  1640                         src = &(__InstPtr(aCollection)->i_instvars[repStartIndex]);
  1650 			src = &(__InstPtr(aCollection)->i_instvars[repStartIndex]);
  1641                         dst = &(__InstPtr(self)->i_instvars[startIndex]);
  1651 			dst = &(__InstPtr(self)->i_instvars[startIndex]);
  1642                         if (aCollection == self) {
  1652 			if (aCollection == self) {
  1643                             /*
  1653 			    /*
  1644                              * no need to check stores if copying
  1654 			     * no need to check stores if copying
  1645                              * from myself
  1655 			     * from myself
  1646                              */
  1656 			     */
  1647 
  1657 
  1648                             /*
  1658 			    /*
  1649                              * take care of overlapping copy
  1659 			     * take care of overlapping copy
  1650                              * do not depend on memset being smart enough
  1660 			     * do not depend on memset being smart enough
  1651                              * (some are not ;-)
  1661 			     * (some are not ;-)
  1652                              */
  1662 			     */
  1653                             if (src < dst) {
  1663 			    if (src < dst) {
  1654                                 /* must do a reverse copy */
  1664 				/* must do a reverse copy */
  1655                                 src += count;
  1665 				src += count;
  1656                                 dst += count;
  1666 				dst += count;
  1657 #ifdef __UNROLL_LOOPS__
  1667 #ifdef __UNROLL_LOOPS__
  1658                                 while (count > 8) {
  1668 				while (count > 8) {
  1659                                     dst[-1] = src[-1];
  1669 				    dst[-1] = src[-1];
  1660                                     dst[-2] = src[-2];
  1670 				    dst[-2] = src[-2];
  1661                                     dst[-3] = src[-3];
  1671 				    dst[-3] = src[-3];
  1662                                     dst[-4] = src[-4];
  1672 				    dst[-4] = src[-4];
  1663                                     dst[-5] = src[-5];
  1673 				    dst[-5] = src[-5];
  1664                                     dst[-6] = src[-6];
  1674 				    dst[-6] = src[-6];
  1665                                     dst[-7] = src[-7];
  1675 				    dst[-7] = src[-7];
  1666                                     dst[-8] = src[-8];
  1676 				    dst[-8] = src[-8];
  1667                                     dst -= 8; src -= 8;
  1677 				    dst -= 8; src -= 8;
  1668                                     count -= 8;
  1678 				    count -= 8;
  1669                                 }
  1679 				}
  1670 #endif
  1680 #endif
  1671                                 while (count-- > 0) {
  1681 				while (count-- > 0) {
  1672                                     *--dst = *--src;
  1682 				    *--dst = *--src;
  1673                                 }
  1683 				}
  1674                                 RETURN ( self );
  1684 				RETURN ( self );
  1675                             }
  1685 			    }
  1676 #ifdef SOFTWARE_PIPELINE
  1686 #ifdef SOFTWARE_PIPELINE
  1677                             {
  1687 			    {
  1678                                 /*
  1688 				/*
  1679                                  * the loop below fetches one longWord behind
  1689 				 * the loop below fetches one longWord behind
  1680                                  * this should not be a problem
  1690 				 * this should not be a problem
  1681                                  */
  1691 				 */
  1682                                 OBJ t1 = src[0];
  1692 				OBJ t1 = src[0];
  1683                                 count--;
  1693 				count--;
  1684                                 if (count) {
  1694 				if (count) {
  1685                                     dst++; src++;
  1695 				    dst++; src++;
  1686                                     do {
  1696 				    do {
  1687                                         dst[-1] = t1;
  1697 					dst[-1] = t1;
  1688                                         t1 = src[0];
  1698 					t1 = src[0];
  1689                                         src++;
  1699 					src++;
  1690                                         dst++;
  1700 					dst++;
  1691                                     } while (count--);
  1701 				    } while (count--);
  1692                                 } else {
  1702 				} else {
  1693                                     dst[0] = t1;
  1703 				    dst[0] = t1;
  1694                                 }
  1704 				}
  1695                             }
  1705 			    }
  1696 #else
  1706 #else
  1697 
  1707 
  1698 # ifdef bcopy4
  1708 # ifdef bcopy4
  1699                             bcopy4(src, dst, count);
  1709 			    bcopy4(src, dst, count);
  1700 # else
  1710 # else
  1701 #  ifdef FAST_MEMCPY
  1711 #  ifdef FAST_MEMCPY
  1702                             memcpy(dst, src, __OBJS2BYTES__(count));
  1712 			    memcpy(dst, src, __OBJS2BYTES__(count));
  1703 #  else
  1713 #  else
  1704 #   ifdef __UNROLL_LOOPS__
  1714 #   ifdef __UNROLL_LOOPS__
  1705                             while (count >= 8) {
  1715 			    while (count >= 8) {
  1706                                 dst[0] = src[0];
  1716 				dst[0] = src[0];
  1707                                 dst[1] = src[1];
  1717 				dst[1] = src[1];
  1708                                 dst[2] = src[2];
  1718 				dst[2] = src[2];
  1709                                 dst[3] = src[3];
  1719 				dst[3] = src[3];
  1710                                 dst[4] = src[4];
  1720 				dst[4] = src[4];
  1711                                 dst[5] = src[5];
  1721 				dst[5] = src[5];
  1712                                 dst[6] = src[6];
  1722 				dst[6] = src[6];
  1713                                 dst[7] = src[7];
  1723 				dst[7] = src[7];
  1714                                 dst += 8; src += 8;
  1724 				dst += 8; src += 8;
  1715                                 count -= 8;
  1725 				count -= 8;
  1716                             }
  1726 			    }
  1717 #   endif
  1727 #   endif
  1718                             while (count--) {
  1728 			    while (count--) {
  1719                                 *dst++ = *src++;
  1729 				*dst++ = *src++;
  1720                             }
  1730 			    }
  1721 #  endif
  1731 #  endif
  1722 # endif
  1732 # endif
  1723 #endif
  1733 #endif
  1724                         } else {
  1734 			} else {
  1725                             REGISTER int spc = __qSpace(self);
  1735 			    REGISTER int spc = __qSpace(self);
  1726 #ifdef __UNROLL_LOOPS__
  1736 #ifdef __UNROLL_LOOPS__
  1727                             while (count >= 8) {
  1737 			    while (count >= 8) {
  1728                                 t = src[0]; dst[0] = t; __STORE_SPC(self, t, spc);
  1738 				t = src[0]; dst[0] = t; __STORE_SPC(self, t, spc);
  1729                                 t = src[1]; dst[1] = t; __STORE_SPC(self, t, spc);
  1739 				t = src[1]; dst[1] = t; __STORE_SPC(self, t, spc);
  1730                                 t = src[2]; dst[2] = t; __STORE_SPC(self, t, spc);
  1740 				t = src[2]; dst[2] = t; __STORE_SPC(self, t, spc);
  1731                                 t = src[3]; dst[3] = t; __STORE_SPC(self, t, spc);
  1741 				t = src[3]; dst[3] = t; __STORE_SPC(self, t, spc);
  1732                                 t = src[4]; dst[4] = t; __STORE_SPC(self, t, spc);
  1742 				t = src[4]; dst[4] = t; __STORE_SPC(self, t, spc);
  1733                                 t = src[5]; dst[5] = t; __STORE_SPC(self, t, spc);
  1743 				t = src[5]; dst[5] = t; __STORE_SPC(self, t, spc);
  1734                                 t = src[6]; dst[6] = t; __STORE_SPC(self, t, spc);
  1744 				t = src[6]; dst[6] = t; __STORE_SPC(self, t, spc);
  1735                                 t = src[7]; dst[7] = t; __STORE_SPC(self, t, spc);
  1745 				t = src[7]; dst[7] = t; __STORE_SPC(self, t, spc);
  1736                                 count -= 8; src += 8; dst += 8;
  1746 				count -= 8; src += 8; dst += 8;
  1737                             }
  1747 			    }
  1738 #endif
  1748 #endif
  1739                             while (count-- > 0) {
  1749 			    while (count-- > 0) {
  1740                                 t = *src++;
  1750 				t = *src++;
  1741                                 *dst++ = t;
  1751 				*dst++ = t;
  1742                                 __STORE_SPC(self, t, spc);
  1752 				__STORE_SPC(self, t, spc);
  1743                             }
  1753 			    }
  1744                         }
  1754 			}
  1745                         RETURN ( self );
  1755 			RETURN ( self );
  1746                     }
  1756 		    }
  1747                 }
  1757 		}
  1748             }
  1758 	    }
  1749 
  1759 
  1750             if (count == 0) {
  1760 	    if (count == 0) {
  1751                 RETURN ( self );
  1761 		RETURN ( self );
  1752             }
  1762 	    }
  1753         }
  1763 	}
  1754     }
  1764     }
  1755 %}.
  1765 %}.
  1756     ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
  1766     ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
  1757 
  1767 
  1758     "Modified: 13.4.1996 / 12:17:13 / cg"
  1768     "Modified: 13.4.1996 / 12:17:13 / cg"
  2688 !
  2698 !
  2689 
  2699 
  2690 version_CVS
  2700 version_CVS
  2691     ^ '$Header$'
  2701     ^ '$Header$'
  2692 ! !
  2702 ! !
  2693