CRCStream.st
changeset 4896 17bbef385be1
parent 4872 002feff60199
child 4897 67e2e9110b81
equal deleted inserted replaced
4895:301653b248c3 4896:17bbef385be1
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "{ Package: 'stx:libbasic2' }"
     1 "{ Package: 'stx:libbasic2' }"
     4 
     2 
     5 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     6 
     4 
     7 HashStream subclass:#CRCStream
     5 HashStream subclass:#CRCStream
   211 
   209 
   212 nextPutBytes:count from:anObject startingAt:start
   210 nextPutBytes:count from:anObject startingAt:start
   213     "add the hash of anObject to the computed hash so far."
   211     "add the hash of anObject to the computed hash so far."
   214 
   212 
   215 %{
   213 %{
       
   214     int len, offs;
       
   215 
       
   216     // fetch first - check later
       
   217     len = __intVal(count);
       
   218     offs = __intVal(start) - 1;
       
   219 
   216     if (__bothSmallInteger(count, start)) {
   220     if (__bothSmallInteger(count, start)) {
   217         int len, offs;
       
   218         int objSize;
   221         int objSize;
   219         unsigned char *extPtr;
   222         unsigned char *extPtr;
   220 
   223 
   221         len = __intVal(count);
   224         // the most common first
   222         offs = __intVal(start) - 1;
   225         if (__isStringLike(anObject)) {
   223 
   226             objSize = __stringSize(anObject);
   224         if (__isExternalBytesLike(anObject)) {
   227             extPtr = (unsigned char *)__stringVal(anObject);
       
   228         } else if (__isByteArray(anObject)) {
       
   229             objSize = __byteArraySize(anObject);
       
   230             extPtr = (unsigned char *)__byteArrayVal(anObject);
       
   231         } else if (__isExternalBytesLike(anObject)) {
   225             OBJ sz = __externalBytesSize(anObject);
   232             OBJ sz = __externalBytesSize(anObject);
   226 
   233 
   227             extPtr = (unsigned char *)__externalBytesAddress(anObject);
   234             extPtr = (unsigned char *)__externalBytesAddress(anObject);
   228             if (__isSmallInteger(sz)) {
   235             if (__isSmallInteger(sz)) {
   229                 objSize = __intVal(sz);
   236                 objSize = __intVal(sz);
   258             unsigned int _crc;
   265             unsigned int _crc;
   259             unsigned int *_crcTable = __integerArrayVal( __INST(crcTable) );
   266             unsigned int *_crcTable = __integerArrayVal( __INST(crcTable) );
   260             unsigned char *cp = extPtr+offs;
   267             unsigned char *cp = extPtr+offs;
   261             unsigned int n = len;
   268             unsigned int n = len;
   262 
   269 
   263             if (__isSmallInteger(__INST(crc))) {
   270             _crc = (unsigned int) (__intVal( __INST(crc) ));
   264                 _crc = (unsigned int) (__intVal( __INST(crc) ));
   271             if (!__isSmallInteger(__INST(crc))) {
   265             } else {
       
   266                 _crc = __unsignedLongIntVal( __INST(crc) );
   272                 _crc = __unsignedLongIntVal( __INST(crc) );
   267             }
   273             }
   268 
   274 
   269 #ifdef __LSBFIRST__
   275 #ifdef __LSBFIRST__
   270 # if __POINTER_SIZE__ == 8
   276 # if __POINTER_SIZE__ == 8
   345 bad: ;
   351 bad: ;
   346 %}.
   352 %}.
   347     self error:'invalid argument'
   353     self error:'invalid argument'
   348 
   354 
   349     "Created: / 09-01-2012 / 16:48:35 / cg"
   355     "Created: / 09-01-2012 / 16:48:35 / cg"
   350     "Modified: / 16-03-2019 / 23:58:21 / Claus Gittinger"
   356     "Modified: / 23-03-2019 / 10:10:07 / Claus Gittinger"
   351 ! !
   357 ! !
   352 
   358 
   353 !CRCStream class methodsFor:'documentation'!
   359 !CRCStream class methodsFor:'documentation'!
   354 
   360 
   355 version_CVS
   361 version_CVS