Array.st
changeset 19750 a753ca25942d
parent 18938 34feead204c2
child 19811 65fec19facb0
child 20149 3edf2e29ed0d
equal deleted inserted replaced
19749:1cde0a794634 19750:a753ca25942d
   549 %}.
   549 %}.
   550     ^ super , aCollection
   550     ^ super , aCollection
   551 !
   551 !
   552 
   552 
   553 copyWith:something
   553 copyWith:something
   554     "return a new collection containing the receivers elements
   554     "return a new collection containing the receiver's elements
   555      and the single new element, newElement.
   555      and the single new element, newElement.
   556      This is different from concatentation, which expects another collection
   556      This is different from concatentation, which expects another collection
   557      as argument, but equivalent to copy-and-addLast.
   557      as argument, but equivalent to copy-and-addLast.
   558      Reimplemented for speed if receiver is an Array.
   558      Reimplemented for speed if receiver is an Array.
   559      (since the inherited copyWith uses replaceFromTo:, which is also
   559      (since the inherited copyWith uses replaceFromTo:, which is also
   565     unsigned INT nIndex;
   565     unsigned INT nIndex;
   566     REGISTER OBJ *srcP, *dstP;
   566     REGISTER OBJ *srcP, *dstP;
   567     REGISTER int spc;
   567     REGISTER int spc;
   568 
   568 
   569     if (__qClass(self) == Array) {
   569     if (__qClass(self) == Array) {
   570 	sz = __qSize(self) + sizeof(OBJ);
   570         sz = __qSize(self) + sizeof(OBJ);
   571 	__PROTECT2__(something, self);
   571         __PROTECT2__(something, self);
   572 	__qAlignedNew(nObj, sz);        /* OBJECT ALLOCATION */
   572         __qAlignedNew(nObj, sz);        /* OBJECT ALLOCATION */
   573 	__UNPROTECT2__(self, something);
   573         __UNPROTECT2__(self, something);
   574 
   574 
   575 	if (nObj) {
   575         if (nObj) {
   576 	    __InstPtr(nObj)->o_class = Array;
   576             __InstPtr(nObj)->o_class = Array;
   577 	    __qSTORE(nObj, Array);
   577             __qSTORE(nObj, Array);
   578 
   578 
   579 	    nIndex = __BYTES2OBJS__(sz - OHDR_SIZE - sizeof(OBJ));
   579             nIndex = __BYTES2OBJS__(sz - OHDR_SIZE - sizeof(OBJ));
   580 	    /*
   580             /*
   581 	     * sorry:
   581              * sorry:
   582 	     *   cannot use bcopy, since we must take care of stores ...
   582              *   cannot use bcopy, since we must take care of stores ...
   583 	     *   could check for: notRemembered + inOld + notLifoRem
   583              *   could check for: notRemembered + inOld + notLifoRem
   584 	     *                  + not incrGCRunning
   584              *                  + not incrGCRunning
   585 	     * but: copyWith is not heavily used by real programmers ...
   585              * but: copyWith is not heavily used by real programmers ...
   586 	     */
   586              */
   587 	    spc = __qSpace(nObj);
   587             spc = __qSpace(nObj);
   588 	    srcP = __arrayVal(self);
   588             srcP = __arrayVal(self);
   589 	    dstP = __arrayVal(nObj);
   589             dstP = __arrayVal(nObj);
   590 
   590 
   591 #ifdef __UNROLL_LOOPS__
   591 #ifdef __UNROLL_LOOPS__
   592 	    while (nIndex >= 4) {
   592             while (nIndex >= 4) {
   593 		OBJ element;
   593                 OBJ element;
   594 
   594 
   595 		element = srcP[0];
   595                 element = srcP[0];
   596 		dstP[0] = element;
   596                 dstP[0] = element;
   597 		__STORE_SPC(nObj, element, spc);
   597                 __STORE_SPC(nObj, element, spc);
   598 		element = srcP[1];
   598                 element = srcP[1];
   599 		dstP[1] = element;
   599                 dstP[1] = element;
   600 		__STORE_SPC(nObj, element, spc);
   600                 __STORE_SPC(nObj, element, spc);
   601 		element = srcP[2];
   601                 element = srcP[2];
   602 		dstP[2] = element;
   602                 dstP[2] = element;
   603 		__STORE_SPC(nObj, element, spc);
   603                 __STORE_SPC(nObj, element, spc);
   604 		element = srcP[3];
   604                 element = srcP[3];
   605 		dstP[3] = element;
   605                 dstP[3] = element;
   606 		__STORE_SPC(nObj, element, spc);
   606                 __STORE_SPC(nObj, element, spc);
   607 		srcP += 4;
   607                 srcP += 4;
   608 		dstP += 4;
   608                 dstP += 4;
   609 		nIndex -= 4;
   609                 nIndex -= 4;
   610 	    }
   610             }
   611 #endif
   611 #endif
   612 	    while (nIndex--) {
   612             while (nIndex--) {
   613 		OBJ element;
   613                 OBJ element;
   614 
   614 
   615 		element = *srcP++;
   615                 element = *srcP++;
   616 		*dstP++ = element;
   616                 *dstP++ = element;
   617 		__STORE_SPC(nObj, element, spc);
   617                 __STORE_SPC(nObj, element, spc);
   618 	    }
   618             }
   619 	    *dstP = something;
   619             *dstP = something;
   620 	    __STORE_SPC(nObj, something, spc);
   620             __STORE_SPC(nObj, something, spc);
   621 	    RETURN ( nObj );
   621             RETURN ( nObj );
   622 	}
   622         }
   623     }
   623     }
   624 %}.
   624 %}.
   625     ^ super copyWith:something
   625     ^ super copyWith:something
   626 ! !
   626 ! !
   627 
   627