--- a/Array.st Wed Nov 15 04:06:32 1995 +0100
+++ b/Array.st Wed Nov 15 04:11:49 1995 +0100
@@ -10,7 +10,7 @@
hereby transferred.
"
-'From Smalltalk/X, Version:2.10.8 on 15-nov-1995 at 04:00:28' !
+'From Smalltalk/X, Version:2.10.8 on 15-nov-1995 at 04:11:36' !
ArrayedCollection variableSubclass:#Array
instanceVariableNames:''
@@ -65,7 +65,7 @@
!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.42 1995-11-15 03:00:38 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.43 1995-11-15 03:11:49 cg Exp $'
! !
!Array class methodsFor:'instance creation'!
@@ -246,62 +246,6 @@
%}
!
-at:index
- "return the indexed instance variable with index, anInteger.
- Reimplemented here to avoid the additional at:->basicAt: send
- (which we can do here, since at: is obviously not redefined in a subclass).
- This method is the same as at:."
-
-%{ /* NOCONTEXT */
-
- REGISTER int indx;
- REGISTER unsigned int nIndex;
- OBJ cls;
-
- if (__isSmallInteger(index)) {
- indx = _intVal(index) - 1;
- if (indx >= 0) {
- nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
- if ((cls = __qClass(self)) != Array)
- indx += _intVal(_ClassInstPtr(cls)->c_ninstvars);
- if (indx < nIndex) {
- RETURN ( _InstPtr(self)->i_instvars[indx] );
- }
- }
- }
-%}.
- ^ super at:index
-!
-
-at:index put:anObject
- "store the 2nd arg, anObject as indexed instvar with index, anInteger.
- Reimplemented here to avoid the additional at:put:->basicAt:put: send
- (which we can do here, since at: is obviously not redefined in a subclass).
- This method is the same as at:."
-
-%{ /* NOCONTEXT */
-
- REGISTER int indx;
- REGISTER unsigned int nIndex;
- OBJ cls;
-
- if (__isSmallInteger(index)) {
- indx = _intVal(index) - 1;
- if (indx >= 0) {
- nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
- if ((cls = __qClass(self)) != Array)
- indx += _intVal(_ClassInstPtr(cls)->c_ninstvars);
- if (indx < nIndex) {
- _InstPtr(self)->i_instvars[indx] = anObject;
- __STORE(self, anObject);
- RETURN ( anObject );
- }
- }
- }
-%}.
- ^ super at:index put:anObject
-!
-
basicSize
"return the number of indexed elements in the receiver"
@@ -363,6 +307,62 @@
%}
.
^ super basicAt:index put:anObject
+!
+
+at:index put:anObject
+ "store the 2nd arg, anObject as indexed instvar with index, anInteger.
+ Reimplemented here to avoid the additional at:put:->basicAt:put: send
+ (which we can do here, since at: is obviously not redefined in a subclass).
+ This method is the same as at:."
+
+%{ /* NOCONTEXT */
+
+ REGISTER int indx;
+ REGISTER unsigned int nIndex;
+ OBJ cls;
+
+ if (__isSmallInteger(index)) {
+ indx = _intVal(index) - 1;
+ if (indx >= 0) {
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ if ((cls = __qClass(self)) != Array)
+ indx += _intVal(_ClassInstPtr(cls)->c_ninstvars);
+ if (indx < nIndex) {
+ _InstPtr(self)->i_instvars[indx] = anObject;
+ __STORE(self, anObject);
+ RETURN ( anObject );
+ }
+ }
+ }
+%}.
+ ^ super at:index put:anObject
+!
+
+at:index
+ "return the indexed instance variable with index, anInteger.
+ Reimplemented here to avoid the additional at:->basicAt: send
+ (which we can do here, since at: is obviously not redefined in a subclass).
+ This method is the same as at:."
+
+%{ /* NOCONTEXT */
+
+ REGISTER int indx;
+ REGISTER unsigned int nIndex;
+ OBJ cls;
+
+ if (__isSmallInteger(index)) {
+ indx = _intVal(index) - 1;
+ if (indx >= 0) {
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ if ((cls = __qClass(self)) != Array)
+ indx += _intVal(_ClassInstPtr(cls)->c_ninstvars);
+ if (indx < nIndex) {
+ RETURN ( _InstPtr(self)->i_instvars[indx] );
+ }
+ }
+ }
+%}.
+ ^ super at:index
! !
!Array methodsFor:'converting'!
@@ -540,6 +540,73 @@
^ super from:start to:stop do:aBlock
!
+keysAndValuesDo:aBlock
+ "evaluate the argument, aBlock for each element in the collection.
+ Pass both index and element to the block.
+ - reimplemented for speed"
+
+ |home|
+%{
+ REGISTER OBJFUNC codeVal;
+ REGISTER int index;
+ unsigned int nIndex;
+ extern OBJ Block;
+ static struct inlineCache val2 = _ILC2;
+ REGISTER OBJ rHome;
+
+ index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ if (__isBlockLike(aBlock)
+ && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
+ && (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(2))) {
+#ifdef NEW_BLOCK_CALL
+ for (; index < nIndex; index++) {
+ if (InterruptPending != nil) __interruptL(@line COMMA_CON);
+
+ (*codeVal)(aBlock, CON_COMMA __MKSMALLINT(index+1),
+ _InstPtr(self)->i_instvars[index]);
+ }
+#else
+ home = _BlockInstPtr(aBlock)->b_home;
+ rHome = home;
+ if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) {
+ /*
+ * home will not move - keep in a fast register
+ */
+ while (index < nIndex) {
+ if (InterruptPending != nil) __interruptL(@line COMMA_CON);
+
+ index++;
+ (*codeVal)(rHome, CON_COMMA __MKSMALLINT(index),
+ _InstPtr(self)->i_instvars[index-1]);
+ }
+ } else {
+ while (index < nIndex) {
+ if (InterruptPending != nil) __interruptL(@line COMMA_CON);
+
+ index++;
+ (*codeVal)(home, CON_COMMA __MKSMALLINT(index),
+ _InstPtr(self)->i_instvars[index-1]);
+ }
+ }
+#endif
+ } else {
+ while (index < nIndex) {
+ if (InterruptPending != nil) __interruptL(@line COMMA_CON);
+
+ index++;
+ (*val2.ilc_func)(aBlock,
+ @symbol(value:value:),
+ CON_COMMA nil, &val2,
+ __MKSMALLINT(index),
+ _InstPtr(self)->i_instvars[index-1]);
+ }
+ }
+%}
+.
+ ^ self
+!
+
do:aBlock
"evaluate the argument, aBlock for each element in the collection.
- reimplemented for speed"
@@ -616,140 +683,6 @@
^ self
!
-nonNilElementsDo:aBlock
- "evaluate the argument, aBlock for each non-nil element"
-
- |home|
-%{
- REGISTER OBJFUNC codeVal;
- REGISTER int index;
- int nIndex;
- extern OBJ Block;
- static struct inlineCache val = _ILC1;
- REGISTER OBJ rHome;
- REGISTER OBJ element;
-
- index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
- nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
- if (__isBlockLike(aBlock)
- && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
- && (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) {
-#ifdef NEW_BLOCK_CALL
- for (; index < nIndex; index++) {
- if (InterruptPending != nil) __interruptL(CONARG);
-
- element = _InstPtr(self)->i_instvars[index];
- if (element != nil)
- (*codeVal)(aBlock, CON_COMMA element);
- }
-#else
- home = _BlockInstPtr(aBlock)->b_home;
- rHome = home;
- if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) {
- /*
- * home will not move - keep in in a register
- */
- for (; index < nIndex; index++) {
- if (InterruptPending != nil) __interruptL(CONARG);
-
- element = _InstPtr(self)->i_instvars[index];
- if (element != nil)
- (*codeVal)(rHome, CON_COMMA element);
- }
- } else {
- for (; index < nIndex; index++) {
- if (InterruptPending != nil) __interruptL(@line CONARG);
-
- element = _InstPtr(self)->i_instvars[index];
- if (element != nil)
- (*codeVal)(home, CON_COMMA element);
- }
- }
-#endif
- } else {
- for (; index < nIndex; index++) {
- if (InterruptPending != nil) __interruptL(@line CONARG);
-
- element = _InstPtr(self)->i_instvars[index];
- if (element != nil)
- (*val.ilc_func)(aBlock,
- @symbol(value:),
- CON_COMMA nil, &val,
- element);
- }
- }
-%}
-.
- ^ self
-!
-
-keysAndValuesDo:aBlock
- "evaluate the argument, aBlock for each element in the collection.
- Pass both index and element to the block.
- - reimplemented for speed"
-
- |home|
-%{
- REGISTER OBJFUNC codeVal;
- REGISTER int index;
- unsigned int nIndex;
- extern OBJ Block;
- static struct inlineCache val2 = _ILC2;
- REGISTER OBJ rHome;
-
- index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
- nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
- if (__isBlockLike(aBlock)
- && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
- && (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(2))) {
-#ifdef NEW_BLOCK_CALL
- for (; index < nIndex; index++) {
- if (InterruptPending != nil) __interruptL(@line COMMA_CON);
-
- (*codeVal)(aBlock, CON_COMMA __MKSMALLINT(index+1),
- _InstPtr(self)->i_instvars[index]);
- }
-#else
- home = _BlockInstPtr(aBlock)->b_home;
- rHome = home;
- if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) {
- /*
- * home will not move - keep in a fast register
- */
- while (index < nIndex) {
- if (InterruptPending != nil) __interruptL(@line COMMA_CON);
-
- index++;
- (*codeVal)(rHome, CON_COMMA __MKSMALLINT(index),
- _InstPtr(self)->i_instvars[index-1]);
- }
- } else {
- while (index < nIndex) {
- if (InterruptPending != nil) __interruptL(@line COMMA_CON);
-
- index++;
- (*codeVal)(home, CON_COMMA __MKSMALLINT(index),
- _InstPtr(self)->i_instvars[index-1]);
- }
- }
-#endif
- } else {
- while (index < nIndex) {
- if (InterruptPending != nil) __interruptL(@line COMMA_CON);
-
- index++;
- (*val2.ilc_func)(aBlock,
- @symbol(value:value:),
- CON_COMMA nil, &val2,
- __MKSMALLINT(index),
- _InstPtr(self)->i_instvars[index-1]);
- }
- }
-%}
-.
- ^ self
-!
-
from:start to:stop reverseDo:aBlock
"evaluate the argument, aBlock for the elements starting at index start
up to (and including) stop in the collection. Step in reverse order.
@@ -819,6 +752,73 @@
^ super from:start to:stop reverseDo:aBlock
!
+nonNilElementsDo:aBlock
+ "evaluate the argument, aBlock for each non-nil element"
+
+ |home|
+%{
+ REGISTER OBJFUNC codeVal;
+ REGISTER int index;
+ int nIndex;
+ extern OBJ Block;
+ static struct inlineCache val = _ILC1;
+ REGISTER OBJ rHome;
+ REGISTER OBJ element;
+
+ index = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ if (__isBlockLike(aBlock)
+ && ((codeVal = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
+ && (_BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) {
+#ifdef NEW_BLOCK_CALL
+ for (; index < nIndex; index++) {
+ if (InterruptPending != nil) __interruptL(CONARG);
+
+ element = _InstPtr(self)->i_instvars[index];
+ if (element != nil)
+ (*codeVal)(aBlock, CON_COMMA element);
+ }
+#else
+ home = _BlockInstPtr(aBlock)->b_home;
+ rHome = home;
+ if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) {
+ /*
+ * home will not move - keep in in a register
+ */
+ for (; index < nIndex; index++) {
+ if (InterruptPending != nil) __interruptL(CONARG);
+
+ element = _InstPtr(self)->i_instvars[index];
+ if (element != nil)
+ (*codeVal)(rHome, CON_COMMA element);
+ }
+ } else {
+ for (; index < nIndex; index++) {
+ if (InterruptPending != nil) __interruptL(@line CONARG);
+
+ element = _InstPtr(self)->i_instvars[index];
+ if (element != nil)
+ (*codeVal)(home, CON_COMMA element);
+ }
+ }
+#endif
+ } else {
+ for (; index < nIndex; index++) {
+ if (InterruptPending != nil) __interruptL(@line CONARG);
+
+ element = _InstPtr(self)->i_instvars[index];
+ if (element != nil)
+ (*val.ilc_func)(aBlock,
+ @symbol(value:),
+ CON_COMMA nil, &val,
+ element);
+ }
+ }
+%}
+.
+ ^ self
+!
+
addAllTo:aCollection
"add all elements of the receiver to aCollection.
return aCollection."
@@ -902,64 +902,6 @@
!Array methodsFor:'filling & replacing'!
-from:index1 to:index2 put:anObject
- "reimplemented for speed if receiver is an Array"
-
-%{ /* NOCONTEXT */
-
- REGISTER int index;
- unsigned int nIndex;
- unsigned int endIndex;
- REGISTER OBJ *dst;
-
- if ((__qClass(self) == Array)
- && __bothSmallInteger(index1, index2)) {
- index = _intVal(index1) - 1;
- if (index >= 0) {
- nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
- endIndex = _intVal(index2) - 1;
- if (endIndex < nIndex) {
- dst = &(_InstPtr(self)->i_instvars[index]);
-#ifdef memset4
- memset4(dst, anObject, (endIndex-index+1));
- __STORE(self, anObject);
-#else
- if ((INT)anObject == 0) {
- memset(dst, 0, __OBJS2BYTES__(endIndex-index+1));
- } else {
-#if defined(UNROLL_LOOPS)
- {
- int i8;
-
- while ((i8 = index + 8) <= endIndex) {
- dst[0] = anObject;
- dst[1] = anObject;
- dst[2] = anObject;
- dst[3] = anObject;
- dst[4] = anObject;
- dst[5] = anObject;
- dst[6] = anObject;
- dst[7] = anObject;
- dst += 8;
- index = i8;
- }
- }
-#endif
- for (; index <= endIndex; index++) {
- *dst++ = anObject;
- }
- __STORE(self, anObject);
- }
-#endif
- RETURN ( self );
- }
- }
- }
-%}
-.
- ^ super from:index1 to:index2 put:anObject
-!
-
replaceFrom:start to:stop with:aCollection startingAt:repStart
"reimplemented for speed if both receiver and aCollection are Arrays"
@@ -1067,6 +1009,64 @@
}
%}.
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
+!
+
+from:index1 to:index2 put:anObject
+ "reimplemented for speed if receiver is an Array"
+
+%{ /* NOCONTEXT */
+
+ REGISTER int index;
+ unsigned int nIndex;
+ unsigned int endIndex;
+ REGISTER OBJ *dst;
+
+ if ((__qClass(self) == Array)
+ && __bothSmallInteger(index1, index2)) {
+ index = _intVal(index1) - 1;
+ if (index >= 0) {
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ endIndex = _intVal(index2) - 1;
+ if (endIndex < nIndex) {
+ dst = &(_InstPtr(self)->i_instvars[index]);
+#ifdef memset4
+ memset4(dst, anObject, (endIndex-index+1));
+ __STORE(self, anObject);
+#else
+ if ((INT)anObject == 0) {
+ memset(dst, 0, __OBJS2BYTES__(endIndex-index+1));
+ } else {
+#if defined(UNROLL_LOOPS)
+ {
+ int i8;
+
+ while ((i8 = index + 8) <= endIndex) {
+ dst[0] = anObject;
+ dst[1] = anObject;
+ dst[2] = anObject;
+ dst[3] = anObject;
+ dst[4] = anObject;
+ dst[5] = anObject;
+ dst[6] = anObject;
+ dst[7] = anObject;
+ dst += 8;
+ index = i8;
+ }
+ }
+#endif
+ for (; index <= endIndex; index++) {
+ *dst++ = anObject;
+ }
+ __STORE(self, anObject);
+ }
+#endif
+ RETURN ( self );
+ }
+ }
+ }
+%}
+.
+ ^ super from:index1 to:index2 put:anObject
! !
!Array methodsFor:'printing & storing'!
@@ -1196,6 +1196,67 @@
^ super identityIndexOf:anElement startingAt:start
!
+indexOf:anElement startingAt:start
+ "search the array for anElement; return index if found, 0 otherwise
+ - reimplemented for speed"
+
+ |element|
+%{
+ REGISTER int index;
+ unsigned int nIndex, nInsts;
+ static struct inlineCache eq = _ILC1;
+
+ if (__isSmallInteger(start)) {
+ index = _intVal(start) - 1;
+ if (index >= 0) {
+ nInsts = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
+ index += nInsts;
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ if (anElement != nil) {
+ while (index < nIndex) {
+ element = _InstPtr(self)->i_instvars[index++];
+ if (element != nil) {
+ if ((element == anElement)
+ || ((*eq.ilc_func)(anElement,
+ @symbol(=),
+ CON_COMMA nil,&eq,
+ element) == true)) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ } else {
+ /* search for nil */
+#if defined(UNROLL_LOOPS)
+ {
+ 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;
+ }
+ }
+#endif
+
+ while (index < nIndex) {
+ if (_InstPtr(self)->i_instvars[index++] == nil) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ }
+ }
+%}.
+ ^ 0
+!
+
includes:anObject
"return true, if the argument, anObject is contained in the array
- reimplemented for speed"
@@ -1280,67 +1341,6 @@
^ false
!
-indexOf:anElement startingAt:start
- "search the array for anElement; return index if found, 0 otherwise
- - reimplemented for speed"
-
- |element|
-%{
- REGISTER int index;
- unsigned int nIndex, nInsts;
- static struct inlineCache eq = _ILC1;
-
- if (__isSmallInteger(start)) {
- index = _intVal(start) - 1;
- if (index >= 0) {
- nInsts = _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars);
- index += nInsts;
- nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
- if (anElement != nil) {
- while (index < nIndex) {
- element = _InstPtr(self)->i_instvars[index++];
- if (element != nil) {
- if ((element == anElement)
- || ((*eq.ilc_func)(anElement,
- @symbol(=),
- CON_COMMA nil,&eq,
- element) == true)) {
- RETURN ( __MKSMALLINT(index - nInsts) );
- }
- }
- }
- } else {
- /* search for nil */
-#if defined(UNROLL_LOOPS)
- {
- 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;
- }
- }
-#endif
-
- while (index < nIndex) {
- if (_InstPtr(self)->i_instvars[index++] == nil) {
- RETURN ( __MKSMALLINT(index - nInsts) );
- }
- }
- }
- }
- }
-%}.
- ^ 0
-!
-
identityIndexOf:anElement or:alternative
"search the array for anElement or alternative;
return the index of anElement if found, or the index of anAlternative,