.
authorclaus
Fri, 19 May 1995 05:55:37 +0200
changeset 353 d4e3e070ee8e
parent 352 09c5eb3915c5
child 354 f8cdd814a21c
.
Array.st
--- a/Array.st	Fri May 19 02:27:57 1995 +0200
+++ b/Array.st	Fri May 19 05:55:37 1995 +0200
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Array.st,v 1.25 1995-05-16 17:05:26 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Array.st,v 1.26 1995-05-19 03:55:37 claus Exp $
 '!
 
 !Array class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Array.st,v 1.25 1995-05-16 17:05:26 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Array.st,v 1.26 1995-05-19 03:55:37 claus Exp $
 "
 !
 
@@ -81,7 +81,7 @@
 
 new:anInteger
     "return an instance of myself with anInteger indexed variables.
-     Since this is often called, its worth gibing it an extra ilc-slot.
+     Since this is often called, its worth giving it an extra ilc-slot.
      Future versions of stc will do this automatically."
 
     ^ self basicNew:anInteger
@@ -220,14 +220,14 @@
 with:one
 %{  /* NOCONTEXT */
     if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) {
-        if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(1))) {
-            OBJ newArray;
+	if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(1))) {
+	    OBJ newArray;
 
-            _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(1));
-            _InstPtr(newArray)->o_class = self;
+	    _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(1));
+	    _InstPtr(newArray)->o_class = self;
 	    _ArrayInstPtr(newArray)->a_element[0] = one;
 	    __STORE(newArray, one);
-            return newArray;
+	    return newArray;
 	}
     }
 %}.
@@ -237,17 +237,17 @@
 with:one with:two
 %{  /* NOCONTEXT */
     if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) {
-        if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(2))) {
-            OBJ newArray;
+	if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(2))) {
+	    OBJ newArray;
 
-            _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(2));
-            _InstPtr(newArray)->o_class = self;
-            _ArrayInstPtr(newArray)->a_element[0] = one;
-            _ArrayInstPtr(newArray)->a_element[1] = two;
-            __STORE(newArray, one);
-            __STORE(newArray, two);
-            return newArray;
-        }
+	    _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(2));
+	    _InstPtr(newArray)->o_class = self;
+	    _ArrayInstPtr(newArray)->a_element[0] = one;
+	    _ArrayInstPtr(newArray)->a_element[1] = two;
+	    __STORE(newArray, one);
+	    __STORE(newArray, two);
+	    return newArray;
+	}
     }
 %}.
     ^ super with:one with:two
@@ -256,19 +256,19 @@
 with:one with:two with:three
 %{  /* NOCONTEXT */
     if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) {
-        if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(3))) {
-            OBJ newArray;
+	if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(3))) {
+	    OBJ newArray;
 
-            _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(3));
-            _InstPtr(newArray)->o_class = self;
-            _ArrayInstPtr(newArray)->a_element[0] = one;
-            _ArrayInstPtr(newArray)->a_element[1] = two;
-            _ArrayInstPtr(newArray)->a_element[2] = three;
-            __STORE(newArray, one);
-            __STORE(newArray, two);
-            __STORE(newArray, three);
-            return newArray;
-        }
+	    _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(3));
+	    _InstPtr(newArray)->o_class = self;
+	    _ArrayInstPtr(newArray)->a_element[0] = one;
+	    _ArrayInstPtr(newArray)->a_element[1] = two;
+	    _ArrayInstPtr(newArray)->a_element[2] = three;
+	    __STORE(newArray, one);
+	    __STORE(newArray, two);
+	    __STORE(newArray, three);
+	    return newArray;
+	}
     }
 %}.
     ^ super with:one with:two with:three
@@ -278,21 +278,21 @@
 
 %{  /* NOCONTEXT */
     if (_ClassInstPtr(self)->c_ninstvars == __MKSMALLINT(0)) {
-        if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(4))) {
-            OBJ newArray;
+	if (_CanDoQuickAlignedNew(sizeof(struct __arrayheader) + __OBJS2BYTES__(4))) {
+	    OBJ newArray;
 
-            _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(4));
-            _InstPtr(newArray)->o_class = self;
-            _ArrayInstPtr(newArray)->a_element[0] = one;
-            _ArrayInstPtr(newArray)->a_element[1] = two;
-            _ArrayInstPtr(newArray)->a_element[2] = three;
-            _ArrayInstPtr(newArray)->a_element[3] = four;
-            __STORE(newArray, one);
-            __STORE(newArray, two);
-            __STORE(newArray, three);
-            __STORE(newArray, four);
-            return newArray;
-        }
+	    _qCheckedAlignedNew(newArray, sizeof(struct __arrayheader) + __OBJS2BYTES__(4));
+	    _InstPtr(newArray)->o_class = self;
+	    _ArrayInstPtr(newArray)->a_element[0] = one;
+	    _ArrayInstPtr(newArray)->a_element[1] = two;
+	    _ArrayInstPtr(newArray)->a_element[2] = three;
+	    _ArrayInstPtr(newArray)->a_element[3] = four;
+	    __STORE(newArray, one);
+	    __STORE(newArray, two);
+	    __STORE(newArray, three);
+	    __STORE(newArray, four);
+	    return newArray;
+	}
     }
 %}.
     ^ super with:one with:two with:three with:four
@@ -309,6 +309,18 @@
 %}
 !
 
+size
+    "return the number of indexed elements in the receiver.
+     Reimplemented here to avoid the additional size->basicSize send
+     (which we can do here, since size is obviously not redefined in a subclass).
+     This method is the same as basicSize."
+
+%{  /* NOCONTEXT */
+
+    RETURN ( __MKSMALLINT(_arraySize(self) - _intVal(_ClassInstPtr(__qClass(self))->c_ninstvars) ));
+%}
+!
+
 basicAt:index
     "return the indexed instance variable with index, anInteger
      - added here for speed"
@@ -335,6 +347,33 @@
     ^ super basicAt:index
 !
 
+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
+!
+
 basicAt:index put:anObject
     "store the 2nd arg, anObject as indexed instvar with index, anInteger.
      - added here for speed"
@@ -361,6 +400,35 @@
 %}
 .
     ^ 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
 ! !
 
 !Array methodsFor:'converting'!