--- a/Array.st Fri Apr 12 17:59:53 1996 +0200
+++ b/Array.st Fri Apr 12 18:01:45 1996 +0200
@@ -1190,41 +1190,100 @@
int nInsts;
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);
- el = anElement;
- op = & (__InstPtr(self)->i_instvars[index]);
+ index = __intVal(start) - 1;
+ if (index >= 0) {
+ nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
+ index += nInsts;
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ el = anElement;
+ op = & (__InstPtr(self)->i_instvars[index]);
#if defined(UNROLL_LOOPS)
- {
- unsigned int i8;
+ {
+ unsigned int i8;
- while ((i8 = index + 8) < nIndex) {
- if (op[0] == el) { RETURN ( __MKSMALLINT(index + 1 - nInsts) ); }
- if (op[1] == el) { RETURN ( __MKSMALLINT(index + 2 - nInsts) ); }
- if (op[2] == el) { RETURN ( __MKSMALLINT(index + 3 - nInsts) ); }
- if (op[3] == el) { RETURN ( __MKSMALLINT(index + 4 - nInsts) ); }
- if (op[4] == el) { RETURN ( __MKSMALLINT(index + 5 - nInsts) ); }
- if (op[5] == el) { RETURN ( __MKSMALLINT(index + 6 - nInsts) ); }
- if (op[6] == el) { RETURN ( __MKSMALLINT(index + 7 - nInsts) ); }
- if (op[7] == el) { RETURN ( __MKSMALLINT(index + 8 - nInsts) ); }
- index = i8;
- op += 8;
- }
- }
+ while ((i8 = index + 8) < nIndex) {
+ if (op[0] == el) { RETURN ( __MKSMALLINT(index + 1 - nInsts) ); }
+ if (op[1] == el) { RETURN ( __MKSMALLINT(index + 2 - nInsts) ); }
+ if (op[2] == el) { RETURN ( __MKSMALLINT(index + 3 - nInsts) ); }
+ if (op[3] == el) { RETURN ( __MKSMALLINT(index + 4 - nInsts) ); }
+ if (op[4] == el) { RETURN ( __MKSMALLINT(index + 5 - nInsts) ); }
+ if (op[5] == el) { RETURN ( __MKSMALLINT(index + 6 - nInsts) ); }
+ if (op[6] == el) { RETURN ( __MKSMALLINT(index + 7 - nInsts) ); }
+ if (op[7] == el) { RETURN ( __MKSMALLINT(index + 8 - nInsts) ); }
+ index = i8;
+ op += 8;
+ }
+ }
#endif
- while (index++ < nIndex) {
- if (*op++ == el) {
- RETURN ( __MKSMALLINT(index - nInsts) );
- }
- }
- RETURN ( __MKSMALLINT(0) );
- }
+ while (index++ < nIndex) {
+ if (*op++ == el) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ RETURN ( __MKSMALLINT(0) );
}
%}.
- ^ super identityIndexOf:anElement startingAt:start
+ ^ self indexNotInteger
+
+
+!
+
+identityIndexOf:anElement startingAt:start endingAt:stop
+ "search the array for anElement in the range start..stop;
+ return the index if found, 0 otherwise.
+ - reimplemented for speed when searching in OrderedCollections"
+
+%{ /* NOCONTEXT */
+
+ REGISTER int index;
+ REGISTER OBJ el;
+ REGISTER OBJ *op;
+ REGISTER unsigned int lastIndex;
+ unsigned int nIndex;
+ int nInsts;
+
+ if (__bothSmallInteger(start, stop)) {
+ index = __intVal(start) - 1;
+ if (index >= 0) {
+ nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
+ index += nInsts;
+ lastIndex = nInsts + __intVal(stop);
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ if (nIndex < lastIndex) {
+ lastIndex = nIndex;
+ }
+ el = anElement;
+ op = & (__InstPtr(self)->i_instvars[index]);
+#if defined(UNROLL_LOOPS)
+ {
+ unsigned int i8;
+
+ while ((i8 = index + 8) < lastIndex) {
+ if (op[0] == el) { RETURN ( __MKSMALLINT(index + 1 - nInsts) ); }
+ if (op[1] == el) { RETURN ( __MKSMALLINT(index + 2 - nInsts) ); }
+ if (op[2] == el) { RETURN ( __MKSMALLINT(index + 3 - nInsts) ); }
+ if (op[3] == el) { RETURN ( __MKSMALLINT(index + 4 - nInsts) ); }
+ if (op[4] == el) { RETURN ( __MKSMALLINT(index + 5 - nInsts) ); }
+ if (op[5] == el) { RETURN ( __MKSMALLINT(index + 6 - nInsts) ); }
+ if (op[6] == el) { RETURN ( __MKSMALLINT(index + 7 - nInsts) ); }
+ if (op[7] == el) { RETURN ( __MKSMALLINT(index + 8 - nInsts) ); }
+ index = i8;
+ op += 8;
+ }
+ }
+#endif
+ while (index++ < lastIndex) {
+ if (*op++ == el) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ RETURN ( __MKSMALLINT(0) );
+ }
+%}.
+ ^ self indexNotInteger
+
!
includes:anObject
@@ -1326,80 +1385,191 @@
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) {
+ 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) {
#define SPECIAL_STRING_OPT
#ifdef SPECIAL_STRING_OPT
- if (__isString(anElement)) {
- while (index < nIndex) {
- element = __InstPtr(self)->i_instvars[index++];
- if (__isNonNilObject(element)) {
- if (element == anElement) {
- RETURN ( __MKSMALLINT(index - nInsts) );
- }
- if (__qClass(element) == @global(String)) {
- if (strcmp(__stringVal(anElement), __stringVal(element)) == 0) {
- RETURN ( __MKSMALLINT(index - nInsts) );
- }
- } else {
- if ((*eq.ilc_func)(anElement, @symbol(=), CON_COMMA nil,&eq, element) == true) {
- RETURN ( __MKSMALLINT(index - nInsts) );
- }
- }
- }
- }
- RETURN (__MKSMALLINT(0));
- }
+ if (__isString(anElement)) {
+ while (index < nIndex) {
+ element = __InstPtr(self)->i_instvars[index++];
+ if (__isNonNilObject(element)) {
+ if (element == anElement) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ if (__qClass(element) == @global(String)) {
+ if (strcmp(__stringVal(anElement), __stringVal(element)) == 0) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ } else {
+ if ((*eq.ilc_func)(anElement, @symbol(=), CON_COMMA nil,&eq, element) == true) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ }
+ RETURN (__MKSMALLINT(0));
+ }
#endif
- 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 */
+ 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;
+ {
+ 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;
- }
- }
+ 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) );
- }
- }
- }
- }
+ while (index < nIndex) {
+ if (__InstPtr(self)->i_instvars[index++] == nil) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ }
+ RETURN (__MKSMALLINT(0));
}
%}.
- ^ 0
+ ^ self indexNotInteger
+
+
+!
+
+indexOf:anElement startingAt:start endingAt:stop
+ "search the array for anElement in the range start..stop;
+ Return the index if found, 0 otherwise.
+ - reimplemented for speed when searching in OrderedCollections"
+
+ |element|
+%{
+ REGISTER int index;
+ unsigned int lastIndex, nIndex, nInsts;
+ static struct inlineCache eq = _ILC1;
+
+ if (__bothSmallInteger(start, stop)) {
+ index = __intVal(start) - 1;
+ if (index >= 0) {
+ nInsts = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars);
+ index += nInsts;
+ lastIndex = nInsts + __intVal(stop);
+ nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE);
+ if (nIndex < lastIndex) {
+ lastIndex = nIndex;
+ }
+
+ if (anElement != nil) {
+#ifdef SPECIAL_STRING_OPT
+ if (__isString(anElement)) {
+ while (index < lastIndex) {
+ element = __InstPtr(self)->i_instvars[index++];
+ if (__isNonNilObject(element)) {
+ if (element == anElement) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ if (__qClass(element) == @global(String)) {
+ if (strcmp(__stringVal(anElement), __stringVal(element)) == 0) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ } else {
+ if ((*eq.ilc_func)(anElement, @symbol(=), CON_COMMA nil,&eq, element) == true) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ }
+ RETURN (__MKSMALLINT(0));
+ }
+#endif
+ while (index < lastIndex) {
+ 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 {
+ if (__isSmallInteger(anElement)) {
+ /* search for a small number */
+ while (index < lastIndex) {
+ element = __InstPtr(self)->i_instvars[index++];
+ if (element == anElement) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ if (!__isSmallInteger(element)) {
+ if ((*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) < lastIndex) {
+ 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 < lastIndex) {
+ if (__InstPtr(self)->i_instvars[index++] == nil) {
+ RETURN ( __MKSMALLINT(index - nInsts) );
+ }
+ }
+ }
+ }
+ }
+ RETURN (__MKSMALLINT(0));
+ }
+%}.
+ ^ self indexNotInteger
! !
!Array class methodsFor:'documentation'!
version
-^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.60 1996-04-09 20:47:05 cg Exp $'! !
+^ '$Header: /cvs/stx/stx/libbasic/Array.st,v 1.61 1996-04-12 16:01:45 cg Exp $'! !