ByteArray.st
changeset 8913 b9498d27a554
parent 8908 68017b13590b
child 8919 707a9ff7f9b2
equal deleted inserted replaced
8912:3d1947a79cf3 8913:b9498d27a554
   364 	    if (indx < 0) goto fail;
   364 	    if (indx < 0) goto fail;
   365 	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   365 	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   366 	}
   366 	}
   367 	nIndex = __byteArraySize(slf);
   367 	nIndex = __byteArraySize(slf);
   368 	if ((unsigned)indx < (unsigned)nIndex) {
   368 	if ((unsigned)indx < (unsigned)nIndex) {
   369 	    RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) );
   369 	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
   370 	}
   370 	}
   371     }
   371     }
   372   fail: ;
   372   fail: ;
   373 %}.
   373 %}.
   374     ^ super basicAt:index
   374     ^ super basicAt:index
   439 	    if (indx < 0) goto badIndex;
   439 	    if (indx < 0) goto badIndex;
   440 	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   440 	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   441 	}
   441 	}
   442 	nIndex = __byteArraySize(slf);
   442 	nIndex = __byteArraySize(slf);
   443 	if ((unsigned)byte < (unsigned)nIndex) {
   443 	if ((unsigned)byte < (unsigned)nIndex) {
   444 	    RETURN ( __MKSMALLINT((__ByteArrayInstPtr(slf)->ba_element[byte] & (1 << indx)) != 0) );
   444 	    RETURN ( __mkSmallInteger(((__ByteArrayInstPtr(slf)->ba_element[byte] & (1 << indx)) != 0)) );
   445 	}
   445 	}
   446     }
   446     }
   447 badIndex: ;
   447 badIndex: ;
   448 %}.
   448 %}.
   449     byteIndex := ((index-1) // 8) + 1.
   449     byteIndex := ((index-1) // 8) + 1.
   597 	    if (indx < 0) goto badIndex;
   597 	    if (indx < 0) goto badIndex;
   598 	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   598 	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
   599 	}
   599 	}
   600 	nIndex = __byteArraySize(slf);
   600 	nIndex = __byteArraySize(slf);
   601 	if ((unsigned)indx < (unsigned)nIndex) {
   601 	if ((unsigned)indx < (unsigned)nIndex) {
   602 	    RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) );
   602 	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
   603 	}
   603 	}
   604     }
   604     }
   605 badIndex: ;
   605 badIndex: ;
   606 %}.
   606 %}.
   607     ^ (super basicAt:index) asInteger
   607     ^ (super basicAt:index) asInteger
   833 		} else {
   833 		} else {
   834 		    val.u_char[0] = byteP[0];
   834 		    val.u_char[0] = byteP[0];
   835 		    val.u_char[1] = byteP[1];
   835 		    val.u_char[1] = byteP[1];
   836 		}
   836 		}
   837 #endif
   837 #endif
   838 		RETURN ( __MKSMALLINT(val.u_ushort) );
   838 		RETURN ( __mkSmallInteger((val.u_ushort)) );
   839 	    }
   839 	    }
   840 	}
   840 	}
   841     }
   841     }
   842 %}.
   842 %}.
   843     ^ super wordAt:index
   843     ^ super wordAt:index
   906 			val = byteP[1];
   906 			val = byteP[1];
   907 			val = (val << 8) + byteP[0];
   907 			val = (val << 8) + byteP[0];
   908 		    }
   908 		    }
   909 #endif
   909 #endif
   910 		}
   910 		}
   911 		RETURN ( __MKSMALLINT(val) );
   911 		RETURN ( __mkSmallInteger(val) );
   912 	    }
   912 	    }
   913 	}
   913 	}
   914     }
   914     }
   915 %}.
   915 %}.
   916     ^ super wordAt:index MSB:msb
   916     ^ super wordAt:index MSB:msb
  3110 	    if (byte > max) {
  3110 	    if (byte > max) {
  3111 		max = byte;
  3111 		max = byte;
  3112 		if (byte == 255) break;
  3112 		if (byte == 255) break;
  3113 	    }
  3113 	    }
  3114 	}
  3114 	}
  3115 	RETURN ( __MKSMALLINT(max) );
  3115 	RETURN ( __mkSmallInteger(max) );
  3116     }
  3116     }
  3117 %}.
  3117 %}.
  3118     ^ super max
  3118     ^ super max
  3119 
  3119 
  3120     "
  3120     "
  3134 %{  /* STACK: 2000 */
  3134 %{  /* STACK: 2000 */
  3135 
  3135 
  3136     REGISTER unsigned char *cp;
  3136     REGISTER unsigned char *cp;
  3137     REGISTER int nByte;
  3137     REGISTER int nByte;
  3138     REGISTER int index;
  3138     REGISTER int index;
  3139     int icounts[256];
  3139     INT icounts[256];
  3140 
  3140 
  3141     if ((__qClass(self) == @global(ByteArray)) && __isArray(counts)) {
  3141     if ((__qClass(self) == @global(ByteArray)) && __isArray(counts)) {
  3142 	/*
  3142 	/*
  3143 	 * zero counts
  3143 	 * zero counts
  3144 	 */
  3144 	 */
  3157 
  3157 
  3158 	/*
  3158 	/*
  3159 	 * make it real counts
  3159 	 * make it real counts
  3160 	 */
  3160 	 */
  3161 	for (index=0; index<256; index++) {
  3161 	for (index=0; index<256; index++) {
  3162 	    __ArrayInstPtr(counts)->a_element[index] = __MKSMALLINT(icounts[index]);
  3162 	    __ArrayInstPtr(counts)->a_element[index] = __mkSmallInteger(icounts[index]);
  3163 	}
  3163 	}
  3164 	RETURN ( counts );
  3164 	RETURN ( counts );
  3165     }
  3165     }
  3166 %}
  3166 %}
  3167 .
  3167 .
  3257      - reimplemented here for speed"
  3257      - reimplemented here for speed"
  3258 
  3258 
  3259 %{  /* NOCONTEXT */
  3259 %{  /* NOCONTEXT */
  3260 
  3260 
  3261     REGISTER unsigned char *cp;
  3261     REGISTER unsigned char *cp;
  3262     REGISTER int index, byteValue;
  3262     REGISTER INT index;
       
  3263     REGISTER int byteValue;
  3263     REGISTER int len;
  3264     REGISTER int len;
  3264     OBJ cls;
  3265     OBJ cls;
  3265 
  3266 
  3266     if (__isSmallInteger(aByte) &&__isBytes(self)) {
  3267     if (__isSmallInteger(aByte) &&__isBytes(self)) {
  3267 	byteValue = __intVal(aByte);
  3268 	byteValue = __intVal(aByte);
  3268 
  3269 
  3269 	if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
  3270 	if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
  3270 	    /*
  3271 	    /*
  3271 	     * searching for something which cannot be found
  3272 	     * searching for something which cannot be found
  3272 	     */
  3273 	     */
  3273 	    RETURN ( __MKSMALLINT(0) );
  3274 	    RETURN ( __mkSmallInteger(0) );
  3274 	}
  3275 	}
  3275 
  3276 
  3276 	if (__isSmallInteger(start)) {
  3277 	if (__isSmallInteger(start)) {
  3277 	    index = __intVal(start);
  3278 	    index = __intVal(start);
  3278 	    len = __byteArraySize(self);
  3279 	    len = __byteArraySize(self);
  3285 		len -= nInst;
  3286 		len -= nInst;
  3286 	    }
  3287 	    }
  3287 	    cp += index - 1;
  3288 	    cp += index - 1;
  3288 	    while (index <= len) {
  3289 	    while (index <= len) {
  3289 		if (*cp == byteValue) {
  3290 		if (*cp == byteValue) {
  3290 		    RETURN ( __MKSMALLINT(index) );
  3291 		    RETURN ( __mkSmallInteger(index) );
  3291 		}
  3292 		}
  3292 		index++;
  3293 		index++;
  3293 		cp++;
  3294 		cp++;
  3294 	    }
  3295 	    }
  3295 	    RETURN ( __MKSMALLINT(0) );
  3296 	    RETURN ( __mkSmallInteger(0) );
  3296 	}
  3297 	}
  3297     }
  3298     }
  3298 %}.
  3299 %}.
  3299     ^ super indexOf:aByte startingAt:start
  3300     ^ super indexOf:aByte startingAt:start
  3300 
  3301 
  3335 ! !
  3336 ! !
  3336 
  3337 
  3337 !ByteArray class methodsFor:'documentation'!
  3338 !ByteArray class methodsFor:'documentation'!
  3338 
  3339 
  3339 version
  3340 version
  3340     ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.169 2005-07-08 14:00:04 cg Exp $'
  3341     ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.170 2005-07-08 17:15:00 cg Exp $'
  3341 ! !
  3342 ! !