ByteArray.st
branchjv
changeset 19354 ec77be1507a3
parent 19225 9e8abf62f932
parent 19350 6eb57a6369be
child 19412 1e842c25e51e
--- a/ByteArray.st	Sat Mar 12 07:23:20 2016 +0000
+++ b/ByteArray.st	Mon Mar 14 08:45:36 2016 +0000
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
@@ -513,11 +515,11 @@
 
 !ByteArray methodsFor:'accessing-longs'!
 
-doubleWordAt:index put:value
+unsignedInt32At:index put:value
     "set the 4-bytes starting at index from the (unsigned) Integer value.
      The value should be in the range 0 to 16rFFFFFFFF
      (for negative values, the stored value is not defined).
-     The value is stored in the machines natural byte order.
+     The value is stored in the machine's natural byte order.
      Q: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
 
     |t|
@@ -527,56 +529,56 @@
     REGISTER int indx;
     int nIndex;
     union {
-	unsigned char u_char[4];
-	unsigned int u_uint;
+        unsigned char u_char[4];
+        unsigned int u_uint;
     } val;
     OBJ cls;
     unsigned char *byteP;
 
     if (__isSmallInteger(index)) {
-	if (__isSmallInteger(value)) {
-	    val.u_uint = __intVal(value);
-	} else {
-	    val.u_uint = __longIntVal(value);
-	    if (val.u_uint == 0) goto error;
-	}
-
-	indx = __intVal(index);
-	if (indx > 0) {
-	    if ((cls = __qClass(self)) != @global(ByteArray))
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    nIndex = __qSize(self) - OHDR_SIZE;
-	    if ((indx+3) <= nIndex) {
-		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
+        if (__isSmallInteger(value)) {
+            val.u_uint = __intVal(value);
+        } else {
+            val.u_uint = __longIntVal(value);
+            if (val.u_uint == 0) goto error;
+        }
+
+        indx = __intVal(index);
+        if (indx > 0) {
+            if ((cls = __qClass(self)) != @global(ByteArray))
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+            nIndex = __qSize(self) - OHDR_SIZE;
+            if ((indx+3) <= nIndex) {
+                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
 #if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
-		((unsigned int *)byteP)[0] = val.u_uint;
+                ((unsigned int *)byteP)[0] = val.u_uint;
 #else
-		if (((unsigned INT)byteP & 3) == 0) {
-		    ((unsigned int *)byteP)[0] = val.u_uint;
-		} else {
-		    byteP[0] = val.u_char[0];
-		    byteP[1] = val.u_char[1];
-		    byteP[2] = val.u_char[2];
-		    byteP[3] = val.u_char[3];
-		}
+                if (((unsigned INT)byteP & 3) == 0) {
+                    ((unsigned int *)byteP)[0] = val.u_uint;
+                } else {
+                    byteP[0] = val.u_char[0];
+                    byteP[1] = val.u_char[1];
+                    byteP[2] = val.u_char[2];
+                    byteP[3] = val.u_char[3];
+                }
 #endif
-		RETURN ( value );
-	    }
-	}
+                RETURN ( value );
+            }
+        }
     }
   error: ;
 %}.
-    ^ super doubleWordAt:index put:value.
+    ^ super unsignedInt32At:index put:value.
 
     "
      |b|
      b := ByteArray new:4.
-     b doubleWordAt:1 put:16r04030201.
+     b unsignedInt32At:1 put:16r04030201.
      b inspect
     "
 !
 
-doubleWordAt:index put:value MSB:msb
+unsignedInt32At:index put:value MSB:msb
     "set the 4-bytes starting at index from the (unsigned) Integer value.
      The value must be in the range 0 to 16rFFFFFFFF.
      The value is stored MSB-first if msb is true; LSB-first otherwise.
@@ -593,82 +595,82 @@
     unsigned char *byteP;
 
     if (__isSmallInteger(index)) {
-	if (__isSmallInteger(value)) {
-	    val = __intVal(value);
-	} else {
-	    val = __longIntVal(value);
-	    if (val == 0) goto error;
-	}
-	indx = __intVal(index);
-	if (indx > 0) {
-	    if ((cls = __qClass(self)) != @global(ByteArray))
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    nIndex = __qSize(self) - OHDR_SIZE;
-	    if ((indx+3) <= nIndex) {
-		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
-		if (msb == true) {
-		    /*
-		     * most significant byte first (i.e sparc order)
-		     */
+        if (__isSmallInteger(value)) {
+            val = __intVal(value);
+        } else {
+            val = __longIntVal(value);
+            if (val == 0) goto error;
+        }
+        indx = __intVal(index);
+        if (indx > 0) {
+            if ((cls = __qClass(self)) != @global(ByteArray))
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+            nIndex = __qSize(self) - OHDR_SIZE;
+            if ((indx+3) <= nIndex) {
+                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
+                if (msb == true) {
+                    /*
+                     * most significant byte first (i.e sparc order)
+                     */
 #if defined(__MSBFIRST__)
-		    if (((INT)byteP & 3) == 0) {
-			((int *)byteP)[0] = val;
-		    } else
+                    if (((INT)byteP & 3) == 0) {
+                        ((int *)byteP)[0] = val;
+                    } else
 #endif
-		    {
-			byteP[3] = val & 0xFF;
-			val >>= 8;
-			byteP[2] = val & 0xFF;
-			val >>= 8;
-			byteP[1] = val & 0xFF;
-			val >>= 8;
-			byteP[0] = val & 0xFF;
-		    }
-		} else {
-		    /*
-		     * least significant byte first (i.e i386/alpha order)
-		     */
+                    {
+                        byteP[3] = val & 0xFF;
+                        val >>= 8;
+                        byteP[2] = val & 0xFF;
+                        val >>= 8;
+                        byteP[1] = val & 0xFF;
+                        val >>= 8;
+                        byteP[0] = val & 0xFF;
+                    }
+                } else {
+                    /*
+                     * least significant byte first (i.e i386/alpha order)
+                     */
 #if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
-		    ((int *)byteP)[0] = val;
+                    ((int *)byteP)[0] = val;
 #else
 # if defined(__LSBFIRST__)
-		    if (((unsigned INT)byteP & 3) == 0) {
-			((int *)byteP)[0] = val;
-		    } else
+                    if (((unsigned INT)byteP & 3) == 0) {
+                        ((int *)byteP)[0] = val;
+                    } else
 # endif
-		    {
-			byteP[0] = val & 0xFF;
-			val >>= 8;
-			byteP[1] = val & 0xFF;
-			val >>= 8;
-			byteP[2] = val & 0xFF;
-			val >>= 8;
-			byteP[3] = val & 0xFF;
-		    }
+                    {
+                        byteP[0] = val & 0xFF;
+                        val >>= 8;
+                        byteP[1] = val & 0xFF;
+                        val >>= 8;
+                        byteP[2] = val & 0xFF;
+                        val >>= 8;
+                        byteP[3] = val & 0xFF;
+                    }
 #endif
-		}
-		RETURN ( value );
-	    }
-	}
+                }
+                RETURN ( value );
+            }
+        }
     }
   error: ;
 %}.
-    ^ super doubleWordAt:index put:value MSB:msb
+    ^ super unsignedInt32At:index put:value MSB:msb
 
     "
      |b|
      b := ByteArray new:8.
-     b doubleWordAt:1 put:16r04030201 MSB:true.
-     b doubleWordAt:5 put:16r04030201 MSB:false.
+     b unsignedInt32At:1 put:16r04030201 MSB:true.
+     b unsignedInt32At:5 put:16r04030201 MSB:false.
      b inspect
     "
 ! !
 
 !ByteArray methodsFor:'accessing-shorts'!
 
-wordAt:index
+unsignedInt16At:index
     "return the 2-bytes starting at index as an (unsigned) Integer.
-     The value is retrieved in the machines natural byte order
+     The value is retrieved in the machine's natural byte order
      Notice: 
         the index is a byte index; thus, this allows for unaligned access to
         words on any boundary.
@@ -695,28 +697,18 @@
 #if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
                 val.u_ushort = ((unsigned short *)byteP)[0];
 #else
-                /*
-                 * mhmh to be measured:
-                 *   the if may hurt more than the additional
-                 *   memory cycles on some machines ...
-                 */
-                if (((INT)byteP & 1) == 0) {
-                    /* aligned */
-                    val.u_ushort = ((unsigned short *)byteP)[0];
-                } else {
-                    val.u_char[0] = byteP[0];
-                    val.u_char[1] = byteP[1];
-                }
+                val.u_char[0] = byteP[0];
+                val.u_char[1] = byteP[1];
 #endif
                 RETURN ( __mkSmallInteger((val.u_ushort)) );
             }
         }
     }
 %}.
-    ^ super wordAt:index
+    ^ super unsignedInt16At:index
 !
 
-wordAt:index MSB:msb
+unsignedInt16At:index MSB:msb
     "return the 2-bytes starting at index as an (unsigned) Integer.
      The value is retrieved MSB (high 8 bits at lower index) if msb is true;
      LSB-first (i.e. low 8-bits at lower byte index) if its false.
@@ -788,13 +780,13 @@
         }
     }
 %}.
-    ^ super wordAt:index MSB:msb
+    ^ super unsignedInt16At:index MSB:msb
 !
 
-wordAt:index put:value
+unsignedInt16At:index put:value
     "set the 2-bytes starting at index from the (unsigned) Integer value.
      The stored value must be in the range 0 .. 16rFFFF.
-     The value is stored in the machines natural byteorder,
+     The value is stored in the machine's natural byteorder,
      i.e. this method should only be used to fill byteArrays which are
      used internally (not passed to other machines).
      Notice: 
@@ -845,18 +837,18 @@
         }
     }
 %}.
-    ^ super wordAt:index put:value
+    ^ super unsignedInt16At:index put:value
 
     "
      |b|
      b := ByteArray new:4.
-     b wordAt:1 put:16r0102.
-     b wordAt:3 put:16r0304.
+     b unsignedInt16At:1 put:16r0102.
+     b unsignedInt16At:3 put:16r0304.
      b inspect
     "
 !
 
-wordAt:index put:value MSB:msb
+unsignedInt16At:index put:value MSB:msb
     "set the 2-bytes starting at index from the (unsigned) Integer value.
      The stored value must be in the range 0 .. 16rFFFF.
      The value is stored LSB-first (i.e. the low 8bits are stored at the
@@ -933,15 +925,15 @@
         }
     }
 %}.
-    ^ super wordAt:index put:value MSB:msb
+    ^ super unsignedInt16At:index put:value MSB:msb
 
     "
      |b|
      b := ByteArray new:8.
-     b wordAt:1 put:16r0102 MSB:false.
-     b wordAt:3 put:16r0304 MSB:false.
-     b wordAt:5 put:16r0102 MSB:true.
-     b wordAt:7 put:16r0304 MSB:true.
+     b unsignedInt16At:1 put:16r0102 MSB:false.
+     b unsignedInt16At:3 put:16r0304 MSB:false.
+     b unsignedInt16At:5 put:16r0102 MSB:true.
+     b unsignedInt16At:7 put:16r0304 MSB:true.
      b inspect
     "
 ! !
@@ -2991,7 +2983,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'searching'!
 
 indexOf:aByte startingAt:start
@@ -3057,7 +3048,6 @@
     "
 ! !
 
-
 !ByteArray methodsFor:'testing'!
 
 isByteArray