#REFACTORING
authorClaus Gittinger <cg@exept.de>
Tue, 15 Mar 2016 22:53:59 +0100
changeset 19368 1811855e8abb
parent 19367 b7eef79ceeb8
child 19369 ccf33c1cd9d8
#REFACTORING class: UninterpretedBytes changed: #shortAt: #shortAt:bigEndian:
UninterpretedBytes.st
--- a/UninterpretedBytes.st	Tue Mar 15 22:46:28 2016 +0100
+++ b/UninterpretedBytes.st	Tue Mar 15 22:53:59 2016 +0100
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-	      All Rights Reserved
+              All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -14,10 +14,10 @@
 "{ NameSpace: Smalltalk }"
 
 ArrayedCollection subclass:#UninterpretedBytes
-	instanceVariableNames:''
-	classVariableNames:'IsBigEndian'
-	poolDictionaries:''
-	category:'Collections-Abstract'
+        instanceVariableNames:''
+        classVariableNames:'IsBigEndian'
+        poolDictionaries:''
+        category:'Collections-Abstract'
 !
 
 !UninterpretedBytes primitiveDefinitions!
@@ -35,26 +35,26 @@
 #define __fetchBytePointerAndSize__(o, pPtr, pSize) \
     {\
       if (__isNonNilObject(o)) { \
-	if (__isByteArrayLike(o)) { \
-	  *(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \
-	  *(pSize) = __byteArraySize(o); \
-	} else if (__qIsExternalBytesLike(o)) { \
-	  OBJ __sz__ = __externalBytesSize(o); \
-	  if (__isSmallInteger(__sz__)) { \
-	    *(pSize) = __intVal(__sz__); \
-	    *(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \
-	  } else { \
-	    *(pSize) = 0; \
-	    *(pPtr) = (unsigned char *)0; \
-	  } \
-	} else { \
-	    *(pSize) /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(o))->c_ninstvars)); \
-	    *(pPtr) = (char *)(__InstPtr(self)) + *(pSize) /* nInstBytes */; \
-	    *(pSize) = __qSize(self) - *(pSize) /* nInstBytes */; \
-	} \
+        if (__isByteArrayLike(o)) { \
+          *(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \
+          *(pSize) = __byteArraySize(o); \
+        } else if (__qIsExternalBytesLike(o)) { \
+          OBJ __sz__ = __externalBytesSize(o); \
+          if (__isSmallInteger(__sz__)) { \
+            *(pSize) = __intVal(__sz__); \
+            *(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \
+          } else { \
+            *(pSize) = 0; \
+            *(pPtr) = (unsigned char *)0; \
+          } \
+        } else { \
+            *(pSize) /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(o))->c_ninstvars)); \
+            *(pPtr) = (char *)(__InstPtr(self)) + *(pSize) /* nInstBytes */; \
+            *(pSize) = __qSize(self) - *(pSize) /* nInstBytes */; \
+        } \
       } else { \
-	*(pSize) = 0; \
-	*(pPtr) = (unsigned char *)0; \
+        *(pSize) = 0; \
+        *(pPtr) = (unsigned char *)0; \
       } \
     }
 
@@ -66,7 +66,7 @@
 copyright
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-	      All Rights Reserved
+              All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -142,9 +142,9 @@
     bytes := self new: sz // 2.
     s := aString readStream.
     1 to: sz // 2 do: [ :idx |
-	hi := s next digitValue.
-	lo := s next digitValue.
-	bytes at:idx put: ((hi bitShift:4) bitOr: lo)
+        hi := s next digitValue.
+        lo := s next digitValue.
+        bytes at:idx put: ((hi bitShift:4) bitOr: lo)
     ].
     ^ bytes
 
@@ -159,7 +159,7 @@
     "
     "
      Time millisecondsToRun:[
-	1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ]
+        1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ]
      ].
     "
 
@@ -172,17 +172,17 @@
      See also fromHexString:, which does something similar, but does not allow for spaces"
 
     ^ self streamContents:[:outStream |
-	|inStream h|
-
-	inStream := aString readStream.
-
-	[
-	    inStream skipSeparators.
-	    inStream atEnd
-	] whileFalse:[
-	    h := inStream next:2.
-	    outStream nextPut:(Integer readFrom:h base:16).
-	].
+        |inStream h|
+
+        inStream := aString readStream.
+
+        [
+            inStream skipSeparators.
+            inStream atEnd
+        ] whileFalse:[
+            h := inStream next:2.
+            outStream nextPut:(Integer readFrom:h base:16).
+        ].
     ].
 
     "
@@ -222,47 +222,47 @@
 
     last := aString last codePoint.
     last > 96 ifTrue:[
-	stop := stop - 3 + (last - 96)
+        stop := stop - 3 + (last - 96)
     ].
     bytes := self new:stop.
 
     index := 1. dstIndex := 1.
     [dstIndex <= stop] whileTrue:[
-	"/ take 4 characters ...
-	"/ allow a line break before each group of 4
-	sixBits := (aString at:index) codePoint.
-	[sixBits < 32] whileTrue:[
-	    index := index + 1.
-	    sixBits := (aString at:index) codePoint.
-	].
-	sixBits := sixBits bitAnd:16r3F.
-	n := sixBits.
-
-	"/ self assert:(aString at:index+1) codePoint >= 32.
-	sixBits := (aString at:index+1) codePoint bitAnd:16r3F.
-	n := (n bitShift:6) + sixBits.
-
-	"/ self assert:(aString at:index+2) codePoint >= 32.
-	sixBits := (aString at:index+2) codePoint bitAnd:16r3F.
-	n := (n bitShift:6) + sixBits.
-
-	"/ self assert:(aString at:index+3) codePoint >= 32.
-	sixBits := (aString at:index+3) codePoint bitAnd:16r3F.
-	n := (n bitShift:6) + sixBits.
-
-	index := index + 4.
-
-	"/ now have 24 bits in n
-
-	bytes at:dstIndex put:(n bitShift:-16).
-
-	dstIndex < stop ifTrue:[
-	    bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF).
-	    dstIndex+2 <= stop ifTrue:[
-		bytes at:dstIndex+2 put:(n bitAnd:16rFF).
-	    ]
-	].
-	dstIndex := dstIndex + 3.
+        "/ take 4 characters ...
+        "/ allow a line break before each group of 4
+        sixBits := (aString at:index) codePoint.
+        [sixBits < 32] whileTrue:[
+            index := index + 1.
+            sixBits := (aString at:index) codePoint.
+        ].
+        sixBits := sixBits bitAnd:16r3F.
+        n := sixBits.
+
+        "/ self assert:(aString at:index+1) codePoint >= 32.
+        sixBits := (aString at:index+1) codePoint bitAnd:16r3F.
+        n := (n bitShift:6) + sixBits.
+
+        "/ self assert:(aString at:index+2) codePoint >= 32.
+        sixBits := (aString at:index+2) codePoint bitAnd:16r3F.
+        n := (n bitShift:6) + sixBits.
+
+        "/ self assert:(aString at:index+3) codePoint >= 32.
+        sixBits := (aString at:index+3) codePoint bitAnd:16r3F.
+        n := (n bitShift:6) + sixBits.
+
+        index := index + 4.
+
+        "/ now have 24 bits in n
+
+        bytes at:dstIndex put:(n bitShift:-16).
+
+        dstIndex < stop ifTrue:[
+            bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF).
+            dstIndex+2 <= stop ifTrue:[
+                bytes at:dstIndex+2 put:(n bitAnd:16rFF).
+            ]
+        ].
+        dstIndex := dstIndex + 3.
     ].
     ^ bytes
 
@@ -281,13 +281,13 @@
      ByteArray fromPackedString:((ByteArray new:64) asPackedString)
 
      0 to:256 do:[:l |
-	|orig copy|
-
-	0 to:255 do:[:fill |
-	    orig := ByteArray new:l withAll:fill.
-	    copy := ByteArray fromPackedString:(orig asPackedString).
-	    self assert:(orig = copy).
-	 ]
+        |orig copy|
+
+        0 to:255 do:[:fill |
+            orig := ByteArray new:l withAll:fill.
+            copy := ByteArray fromPackedString:(orig asPackedString).
+            self assert:(orig = copy).
+         ]
      ]
     "
 
@@ -314,72 +314,72 @@
     REGISTER OBJ *op;
 
     if (__isSmallInteger(anInteger)) {
-	nindexedinstvars = __intVal(anInteger);
-	if (nindexedinstvars >= 0) {
-	    if (self == ByteArray) {
-		/*
-		 * the most common case
-		 */
-		instsize = OHDR_SIZE + nindexedinstvars;
-		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
-		    __qCheckedNew(newobj, instsize);
-		    __InstPtr(newobj)->o_class = self;
-		    __qSTORE(newobj, self);
-		    RETURN (newobj );
-		}
-	    } else {
-		/*
-		 * Take care for subclasses like TwoByteString
-		 */
-		switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) {
-		case BYTEARRAY:
-		    break;
-
-		case WORDARRAY:
-		case SWORDARRAY:
-		    nindexedinstvars *= 2;
-		    break;
-
-		case LONGARRAY:
-		case SLONGARRAY:
-		    nindexedinstvars *= 4;
-		    break;
-
-		default:
-		    /* don't know about this array type, delegate to super */
-		    goto out;
-		}
-	    }
-	    nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
-	    instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
-	    __PROTECT_CONTEXT__
-	    __qNew(newobj, instsize);   /* OBJECT ALLOCATION */
-	    __UNPROTECT_CONTEXT__
-	    if (newobj != nil) {
-		__InstPtr(newobj)->o_class = self;
-		__qSTORE(newobj, self);
-		if (nInstVars) {
-		    /*
-		     * still have to nil out named instvars ...
-		     */
+        nindexedinstvars = __intVal(anInteger);
+        if (nindexedinstvars >= 0) {
+            if (self == ByteArray) {
+                /*
+                 * the most common case
+                 */
+                instsize = OHDR_SIZE + nindexedinstvars;
+                if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
+                    __qCheckedNew(newobj, instsize);
+                    __InstPtr(newobj)->o_class = self;
+                    __qSTORE(newobj, self);
+                    RETURN (newobj );
+                }
+            } else {
+                /*
+                 * Take care for subclasses like TwoByteString
+                 */
+                switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) {
+                case BYTEARRAY:
+                    break;
+
+                case WORDARRAY:
+                case SWORDARRAY:
+                    nindexedinstvars *= 2;
+                    break;
+
+                case LONGARRAY:
+                case SLONGARRAY:
+                    nindexedinstvars *= 4;
+                    break;
+
+                default:
+                    /* don't know about this array type, delegate to super */
+                    goto out;
+                }
+            }
+            nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
+            instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
+            __PROTECT_CONTEXT__
+            __qNew(newobj, instsize);   /* OBJECT ALLOCATION */
+            __UNPROTECT_CONTEXT__
+            if (newobj != nil) {
+                __InstPtr(newobj)->o_class = self;
+                __qSTORE(newobj, self);
+                if (nInstVars) {
+                    /*
+                     * still have to nil out named instvars ...
+                     */
 #if defined(memset4) && defined(FAST_OBJECT_MEMSET4)
-		    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
+                    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
 #else
 # if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES)
-		    /*
-		     * knowing that nil is 0
-		     */
-		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
+                    /*
+                     * knowing that nil is 0
+                     */
+                    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
 # else
-		    op = __InstPtr(newobj)->i_instvars;
-		    while (nInstVars--)
-			*op++ = nil;
+                    op = __InstPtr(newobj)->i_instvars;
+                    while (nInstVars--)
+                        *op++ = nil;
 # endif
 #endif
-		}
-		RETURN ( newobj );
-	    }
-	}
+                }
+                RETURN ( newobj );
+            }
+        }
     }
 out:;
 %}.
@@ -418,7 +418,7 @@
      I.e. false for vax, intel; true for m68k, sun.
 
      Notice: UninterpretedBytes isBigEndian
-	     this is inlined both by stc and the jit compiler"
+             this is inlined both by stc and the jit compiler"
 
 %{  /* NOCONTEXT */
 
@@ -439,8 +439,8 @@
      *    constant for systems where this is known.
      */
     union {
-	unsigned int   u_l;
-	char           u_c[sizeof(int)];
+        unsigned int   u_l;
+        char           u_c[sizeof(int)];
     } u;
 
     u.u_l = 0x87654321;
@@ -840,7 +840,7 @@
      This may be worth a primitive.
      This is the ST80 equivalent of #signedWordAt:"
 
-    ^ (self unsignedInt16At:index MSB:IsBigEndian) signExtendedShortValue
+    ^ self signedInt16At:index MSB:IsBigEndian
 
     "
      |b|
@@ -861,7 +861,7 @@
      LSB-first otherwise.
      This is the ST80 equivalent of #signedWordAt:"
 
-    ^ (self unsignedInt16At:index MSB:msb) signExtendedShortValue
+    ^ self signedInt16At:index MSB:msb
 
     "
      |b|
@@ -1725,7 +1725,7 @@
      (i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)"
 
     (aNumber between:0 and:99) ifFalse:[
-	self error:'invalid value for BCD encoding'
+        self error:'invalid value for BCD encoding'
     ].
     ^ self byteAt:index put:aNumber encodeAsBCD
 
@@ -2480,41 +2480,41 @@
 
 %{
     if (__isSmallInteger(index)) {
-	unsigned char *cp;
-	INT sz;
-
-	__fetchBytePointerAndSize__(self, &cp, &sz);
-	if (cp) {
-	    unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1;
-	    char *pointer;
-
-	    if ((idx+(sizeof(pointer)-1)) < sz) {
-		cp += idx;
-		/*
-		 * aligned
-		 */
-		if (((INT)cp & (sizeof(pointer)-1)) == 0) {
-		    pointer = ((char **)cp)[0];
-		    RETURN (__MKEXTERNALADDRESS(pointer));
-		} else {
+        unsigned char *cp;
+        INT sz;
+
+        __fetchBytePointerAndSize__(self, &cp, &sz);
+        if (cp) {
+            unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1;
+            char *pointer;
+
+            if ((idx+(sizeof(pointer)-1)) < sz) {
+                cp += idx;
+                /*
+                 * aligned
+                 */
+                if (((INT)cp & (sizeof(pointer)-1)) == 0) {
+                    pointer = ((char **)cp)[0];
+                    RETURN (__MKEXTERNALADDRESS(pointer));
+                } else {
 #if 0
-		    printf("cp UNALIGNED (%"_lx_")\n", (INT)cp);
+                    printf("cp UNALIGNED (%"_lx_")\n", (INT)cp);
 #endif
-		}
-	    } else {
+                }
+            } else {
 #if 0
-		printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n",
-			idx, (int)(sizeof(pointer)-1), sz);
+                printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n",
+                        idx, (int)(sizeof(pointer)-1), sz);
 #endif
-	    }
-	} else {
+            }
+        } else {
 #if 0
-	    printf("cp is NULL\n");
+            printf("cp is NULL\n");
 #endif
-	}
+        }
     } else {
 #if 0
-	printf("bad index\n");
+        printf("bad index\n");
 #endif
     }
 bad:;
@@ -2541,40 +2541,40 @@
     OBJ *pointer;
 
     if (__isExternalAddressLike(value)) {
-	pointer = __externalAddressVal(value);
+        pointer = __externalAddressVal(value);
     } else if (__isExternalBytesLike(value)) {
-	pointer = __externalBytesVal(value);
-	if (pointer == (OBJ *)0)
-	    pointer = 0;
+        pointer = __externalBytesVal(value);
+        if (pointer == (OBJ *)0)
+            pointer = 0;
     } else if (value == nil) {
-	pointer = 0;
+        pointer = 0;
     } else if (__isSmallInteger(value)) {
-	pointer = (OBJ *)__intVal(value);
+        pointer = (OBJ *)__intVal(value);
     } else {
-	if ((pointer = (OBJ *)__unsignedLongIntVal(value)) == 0) {
-	    goto bad;
-	}
+        if ((pointer = (OBJ *)__unsignedLongIntVal(value)) == 0) {
+            goto bad;
+        }
     }
 
     if (__isSmallInteger(index)) {
-	unsigned char *cp;
-	INT sz;
-
-	__fetchBytePointerAndSize__(self, &cp, &sz);
-	if (cp) {
-	    unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1;
-
-	    if ((idx+(sizeof(pointer)-1)) < sz) {
-		cp += idx;
-		/*
-		 * aligned
-		 */
-		if (((INT)cp & (sizeof(pointer)-1)) == 0) {
-		    ((char **)cp)[0] = (char *) pointer;
-		    RETURN (value);
-		}
-	    }
-	}
+        unsigned char *cp;
+        INT sz;
+
+        __fetchBytePointerAndSize__(self, &cp, &sz);
+        if (cp) {
+            unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1;
+
+            if ((idx+(sizeof(pointer)-1)) < sz) {
+                cp += idx;
+                /*
+                 * aligned
+                 */
+                if (((INT)cp & (sizeof(pointer)-1)) == 0) {
+                    ((char **)cp)[0] = (char *) pointer;
+                    RETURN (value);
+                }
+            }
+        }
     }
 bad:;
 %}.
@@ -3464,8 +3464,8 @@
     stream := WriteStream on:(String new:40).
     i := index.
     [(c := self byteAt:i) ~~ 0] whileTrue:[
-	stream nextPut:(Character value:c).
-	i := i + 1.
+        stream nextPut:(Character value:c).
+        i := i + 1.
     ].
     ^ stream contents
 
@@ -3570,11 +3570,11 @@
     max := start + maxSize - 1.
 
     start to:max do:[:eachIndex|
-	c := self byteAt:eachIndex.
-	c == 0 ifTrue:[
-	    ^ stream contents
-	].
-	stream nextPut:(Character value:c).
+        c := self byteAt:eachIndex.
+        c == 0 ifTrue:[
+            ^ stream contents
+        ].
+        stream nextPut:(Character value:c).
     ].
     ^ stream contents
 
@@ -3677,8 +3677,8 @@
     cls := self class.
 
     (cls == ByteArray or:[cls == ImmutableByteArray or:[cls == ExternalBytes]]) ifTrue:[
-	size := self size.
-	^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1.
+        size := self size.
+        ^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1.
     ].
     ^ super asString.
 
@@ -3714,12 +3714,12 @@
       |utf8Encoding original readBack|
 
       1 to:16rFFFF do:[:ascii |
-	original := (Character value:ascii) asString.
-	utf8Encoding := original utf8Encoded.
-	readBack := utf8Encoding utf8Decoded.
-	readBack = original ifFalse:[
-	    self halt
-	]
+        original := (Character value:ascii) asString.
+        utf8Encoding := original utf8Encoded.
+        readBack := utf8Encoding utf8Decoded.
+        readBack = original ifFalse:[
+            self halt
+        ]
       ]
     "
 !
@@ -3732,26 +3732,26 @@
     |in out c|
 
     self containsNon7BitAscii ifFalse:[
-	^ self asSingleByteString
+        ^ self asSingleByteString
     ].
 
     out := WriteStream on:(String uninitializedNew:self size * 3 // 2).
     in := self readStream.
     [in atEnd] whileFalse:[
-	c := Character utf8DecodeFrom:in.
-	c codePoint > 16rFF ifTrue:[
-	    c := replacementCharacter
-	].
-	out nextPut:c.
+        c := Character utf8DecodeFrom:in.
+        c codePoint > 16rFF ifTrue:[
+            c := replacementCharacter
+        ].
+        out nextPut:c.
     ].
     ^ out contents
 
     "
      (Character value:16r220) utf8Encoded
-	utf8DecodedWithTwoByteCharactersReplacedBy:(Character space)
+        utf8DecodedWithTwoByteCharactersReplacedBy:(Character space)
 
      (Character value:16r220) utf8Encoded asExternalBytes copyButLast
-	utf8DecodedWithTwoByteCharactersReplacedBy:(Character space)
+        utf8DecodedWithTwoByteCharactersReplacedBy:(Character space)
     "
 ! !
 
@@ -3779,142 +3779,142 @@
      && (__isBytes(self) || __isWords(self))
      && __bothSmallInteger(start, stop)
      && __isSmallInteger(repStart)) {
-	startIndex = __intVal(start) - 1;
-	if (startIndex >= 0) {
-	    dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex;
-	    nIndex = __byteArraySize(self);
-
-	    if ((cls = __qClass(self)) != @global(ByteArray)) {
-		int nInst;
-
-		nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-		dst += nInst;
-		nIndex -= nInst;
-	    }
-
-	    stopIndex = __intVal(stop) - 1;
-	    count = stopIndex - startIndex + 1;
-	    if (count == 0) {
-		RETURN ( self );
-	    }
-
-	    if ((count > 0) && (stopIndex < nIndex)) {
-		repStartIndex = __intVal(repStart) - 1;
-		if (repStartIndex >= 0) {
-		    if (__isExternalBytesLike(aCollection)) {
-			OBJ sz;
-
-			src = __externalAddressVal(aCollection);
-			if (src == 0) goto fallBack;
-
-			sz = __externalBytesSize(aCollection);
-			if (__isSmallInteger(sz)) {
-			    repNIndex = __smallIntegerVal(sz);
-			} else {
-			    repNIndex = repStopIndex+1; /* always enough */
-			}
-			src = src + repStartIndex;
-		    } else {
-			if (__isStringLike(aCollection)) {
-			    repNIndex = __stringSize(aCollection);
-			} else {
-			    repNIndex = __qSize(aCollection) - OHDR_SIZE;
-			}
-			src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex;
-			if ((cls = __qClass(aCollection)) != @global(ByteArray)) {
-			    int nInst;
-
-			    nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-			    src += nInst;
-			    repNIndex -= nInst;
-			}
-		    }
-		    repStopIndex = repStartIndex + (stopIndex - startIndex);
-		    if (repStopIndex < repNIndex) {
-			if (aCollection == self) {
-			    /* take care of overlapping copy */
-			    if (src < dst) {
-				/* must do a reverse copy */
-				src += count;
-				dst += count;
-				while (count-- > 0) {
-				    *--dst = *--src;
-				}
-				RETURN ( self );
-			    }
-			}
+        startIndex = __intVal(start) - 1;
+        if (startIndex >= 0) {
+            dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex;
+            nIndex = __byteArraySize(self);
+
+            if ((cls = __qClass(self)) != @global(ByteArray)) {
+                int nInst;
+
+                nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+                dst += nInst;
+                nIndex -= nInst;
+            }
+
+            stopIndex = __intVal(stop) - 1;
+            count = stopIndex - startIndex + 1;
+            if (count == 0) {
+                RETURN ( self );
+            }
+
+            if ((count > 0) && (stopIndex < nIndex)) {
+                repStartIndex = __intVal(repStart) - 1;
+                if (repStartIndex >= 0) {
+                    if (__isExternalBytesLike(aCollection)) {
+                        OBJ sz;
+
+                        src = __externalAddressVal(aCollection);
+                        if (src == 0) goto fallBack;
+
+                        sz = __externalBytesSize(aCollection);
+                        if (__isSmallInteger(sz)) {
+                            repNIndex = __smallIntegerVal(sz);
+                        } else {
+                            repNIndex = repStopIndex+1; /* always enough */
+                        }
+                        src = src + repStartIndex;
+                    } else {
+                        if (__isStringLike(aCollection)) {
+                            repNIndex = __stringSize(aCollection);
+                        } else {
+                            repNIndex = __qSize(aCollection) - OHDR_SIZE;
+                        }
+                        src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex;
+                        if ((cls = __qClass(aCollection)) != @global(ByteArray)) {
+                            int nInst;
+
+                            nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+                            src += nInst;
+                            repNIndex -= nInst;
+                        }
+                    }
+                    repStopIndex = repStartIndex + (stopIndex - startIndex);
+                    if (repStopIndex < repNIndex) {
+                        if (aCollection == self) {
+                            /* take care of overlapping copy */
+                            if (src < dst) {
+                                /* must do a reverse copy */
+                                src += count;
+                                dst += count;
+                                while (count-- > 0) {
+                                    *--dst = *--src;
+                                }
+                                RETURN ( self );
+                            }
+                        }
 
 # ifdef bcopy4
-			if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) {
-			    int nW;
-
-			    /* copy unaligned part */
-			    while (count && ((unsigned INT)src & 3)) {
-				*dst++ = *src++;
-				count--;
-			    }
-
-			    if (count > 0) {
-				/* copy aligned part */
-				nW = count >> 2;
-				bcopy4(src, dst, nW);
-				if ((count = count & 3) != 0) {
-				    /* copy any remaining part */
-				    src += (nW<<2);
-				    dst += (nW<<2);
-				    while (count--) {
-					*dst++ = *src++;
-				    }
-				}
-			    }
-			    RETURN ( self );
-			}
+                        if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) {
+                            int nW;
+
+                            /* copy unaligned part */
+                            while (count && ((unsigned INT)src & 3)) {
+                                *dst++ = *src++;
+                                count--;
+                            }
+
+                            if (count > 0) {
+                                /* copy aligned part */
+                                nW = count >> 2;
+                                bcopy4(src, dst, nW);
+                                if ((count = count & 3) != 0) {
+                                    /* copy any remaining part */
+                                    src += (nW<<2);
+                                    dst += (nW<<2);
+                                    while (count--) {
+                                        *dst++ = *src++;
+                                    }
+                                }
+                            }
+                            RETURN ( self );
+                        }
 # else
 #  if __POINTER_SIZE__ == 8
-			if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) {
-			    /* copy unaligned part */
-			    while (count && ((unsigned INT)src & 7)) {
-				*dst++ = *src++;
-				count--;
-			    }
-
-			    /* copy aligned part */
-			    while (count >= 8) {
-				((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0];
-				dst += 8;
-				src += 8;
-				count -= 8;
-			    }
-			    while (count--) {
-				*dst++ = *src++;
-			    }
-			    RETURN ( self );
-			}
+                        if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) {
+                            /* copy unaligned part */
+                            while (count && ((unsigned INT)src & 7)) {
+                                *dst++ = *src++;
+                                count--;
+                            }
+
+                            /* copy aligned part */
+                            while (count >= 8) {
+                                ((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0];
+                                dst += 8;
+                                src += 8;
+                                count -= 8;
+                            }
+                            while (count--) {
+                                *dst++ = *src++;
+                            }
+                            RETURN ( self );
+                        }
 #  endif /* 64bit */
 # endif /* bcopy4 */
 
 # ifdef FAST_MEMCPY
-			bcopy(src, dst, count);
+                        bcopy(src, dst, count);
 # else
 #  ifdef __UNROLL_LOOPS__
-			while (count >= 8) {
-			    dst[0] = src[0]; dst[1] = src[1];
-			    dst[2] = src[2]; dst[3] = src[3];
-			    dst[4] = src[4]; dst[5] = src[5];
-			    dst[6] = src[6]; dst[7] = src[7];
-			    dst += 8; src += 8;
-			    count -= 8;
-			}
+                        while (count >= 8) {
+                            dst[0] = src[0]; dst[1] = src[1];
+                            dst[2] = src[2]; dst[3] = src[3];
+                            dst[4] = src[4]; dst[5] = src[5];
+                            dst[6] = src[6]; dst[7] = src[7];
+                            dst += 8; src += 8;
+                            count -= 8;
+                        }
 #  endif /* __UNROLL_LOOPS__ */
-			while (count-- > 0) {
-			    *dst++ = *src++;
-			}
+                        while (count-- > 0) {
+                            *dst++ = *src++;
+                        }
 # endif
-			RETURN ( self );
-		    }
-		}
-	    }
-	}
+                        RETURN ( self );
+                    }
+                }
+            }
+        }
     }
 fallBack: ;
 #endif
@@ -3927,34 +3927,34 @@
 
     "
      #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-	copy
-	    replaceFrom:1 to:8
-	    with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-	    startingAt:1
+        copy
+            replaceFrom:1 to:8
+            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+            startingAt:1
 
      #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-	copy
-	    replaceFrom:3 to:10
-	    with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-	    startingAt:1
+        copy
+            replaceFrom:3 to:10
+            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+            startingAt:1
 
      #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-	copy
-	    replaceFrom:3 to:4
-	    with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-	    startingAt:1
+        copy
+            replaceFrom:3 to:4
+            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+            startingAt:1
 
      #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-	copy
-	    replaceFrom:0 to:9
-	    with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-	    startingAt:1
+        copy
+            replaceFrom:0 to:9
+            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+            startingAt:1
 
      #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
-	copy
-	    replaceFrom:1 to:10
-	    with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
-	    startingAt:0
+        copy
+            replaceFrom:1 to:10
+            with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+            startingAt:0
     "
 !
 
@@ -3966,15 +3966,15 @@
      therefore the change may affect all others referencing the receiver."
 
     ^ self
-	replaceBytesFrom:startIndex
-	to:(startIndex + replacementCollection size - repStartIndex)
-	with:replacementCollection
-	startingAt:repStartIndex
+        replaceBytesFrom:startIndex
+        to:(startIndex + replacementCollection size - repStartIndex)
+        with:replacementCollection
+        startingAt:repStartIndex
 
     "
      args:    startIndex            : <integer>
-	      replacementCollection : <collection of <bytes> >
-	      repStartIndex         : <integer>
+              replacementCollection : <collection of <bytes> >
+              repStartIndex         : <integer>
 
      returns: self
     "
@@ -3991,10 +3991,10 @@
      therefore the change may affect all others referencing the receiver."
 
     ^ self
-	replaceBytesFrom:1
-	to:(replacementCollection size min:self size)
-	with:replacementCollection
-	startingAt:1
+        replaceBytesFrom:1
+        to:(replacementCollection size min:self size)
+        with:replacementCollection
+        startingAt:1
 
     "
      (ByteArray new:10) replaceBytesWith:'hello'
@@ -4013,18 +4013,18 @@
      therefore the change may affect all others referencing the receiver."
 
     self class isBytes ifTrue:[
-	((aCollection class == self class)
-	 or:[aCollection isByteCollection]) ifTrue:[
-	    ^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
-	].
+        ((aCollection class == self class)
+         or:[aCollection isByteCollection]) ifTrue:[
+            ^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
+        ].
     ].
     ^ super replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
 
     "
      args:    startIndex            : <integer>
-	      stopIndex             : <integer>
-	      replacementCollection : <collection of <bytes> >
-	      repStartIndex         : <integer>
+              stopIndex             : <integer>
+              replacementCollection : <collection of <bytes> >
+              repStartIndex         : <integer>
 
      returns: self
     "
@@ -4040,94 +4040,94 @@
      If endindex = 0 or endIndex > size, hash up the size.
 
      NOTE: startIndex and endIndex are only hints about what should be hashed.
-	   In fact, more bytes could be involved in hashing.
-	   SO ARRAYS MUST BE EQUAL TO HASH TO THE SAME VALUE"
+           In fact, more bytes could be involved in hashing.
+           SO ARRAYS MUST BE EQUAL TO HASH TO THE SAME VALUE"
 
     |w|
 
 %{
     if (__bothSmallInteger(startIndex, endIndex)) {
-	unsigned char *cp;
-	INT sz;
-
-	__fetchBytePointerAndSize__(self, &cp, &sz);
-	if (cp) {
-	    INT sidx = ((unsigned INT)__smallIntegerVal(startIndex)) - 1;
-	    INT eidx = ((unsigned INT)__smallIntegerVal(endIndex)) - 1;
-	    unsigned char *ep;
-	    unsigned INT hash = 0, hash2 = 0, carry;
-	    int i;
-
-	    if (eidx < 0 || eidx >= sz) eidx = sz - 1;
-	    if (sidx > eidx) sidx = eidx;
-	    if (sidx < 0) {
-		RETURN(__mkSmallInteger(0));
-	    }
-
-	    ep = cp + eidx;
-	    cp += sidx;
+        unsigned char *cp;
+        INT sz;
+
+        __fetchBytePointerAndSize__(self, &cp, &sz);
+        if (cp) {
+            INT sidx = ((unsigned INT)__smallIntegerVal(startIndex)) - 1;
+            INT eidx = ((unsigned INT)__smallIntegerVal(endIndex)) - 1;
+            unsigned char *ep;
+            unsigned INT hash = 0, hash2 = 0, carry;
+            int i;
+
+            if (eidx < 0 || eidx >= sz) eidx = sz - 1;
+            if (sidx > eidx) sidx = eidx;
+            if (sidx < 0) {
+                RETURN(__mkSmallInteger(0));
+            }
+
+            ep = cp + eidx;
+            cp += sidx;
 
 #if 0
-	    /*
-	     * On LSB-First (little endian) cpus,
-	     * this code does not produce the same result
-	     * if the same bytes are at different positions
-	     */
-
-	    if ((INT)cp & (sizeof(INT)-1)) {
-		/* not aligned */
-
-		for (i=0; cp <= ep; cp++) {
-		    hash2 = (hash2 << 8) | *cp;
-		    if (++i == sizeof(INT)) {
-			hash ^= hash2;
-			i = hash2 = 0;
-		    }
-		}
-	    } else {
-		/* aligned */
-		for (; cp+sizeof(INT) <= ep; cp += sizeof(INT)) {
-		    hash ^= *(unsigned INT *)cp;
-		}
-		for (; cp <= ep; cp++) {
-		    hash2 = (hash2 << 8) | *cp;
-		}
-	    }
+            /*
+             * On LSB-First (little endian) cpus,
+             * this code does not produce the same result
+             * if the same bytes are at different positions
+             */
+
+            if ((INT)cp & (sizeof(INT)-1)) {
+                /* not aligned */
+
+                for (i=0; cp <= ep; cp++) {
+                    hash2 = (hash2 << 8) | *cp;
+                    if (++i == sizeof(INT)) {
+                        hash ^= hash2;
+                        i = hash2 = 0;
+                    }
+                }
+            } else {
+                /* aligned */
+                for (; cp+sizeof(INT) <= ep; cp += sizeof(INT)) {
+                    hash ^= *(unsigned INT *)cp;
+                }
+                for (; cp <= ep; cp++) {
+                    hash2 = (hash2 << 8) | *cp;
+                }
+            }
 #else
-	    for (i=0; cp <= ep-sizeof(INT); cp += sizeof(INT)) {
-		hash2 = cp[0];
-		hash2 = (hash2 << 8) | cp[1];
-		hash2 = (hash2 << 8) | cp[2];
-		hash2 = (hash2 << 8) | cp[3];
+            for (i=0; cp <= ep-sizeof(INT); cp += sizeof(INT)) {
+                hash2 = cp[0];
+                hash2 = (hash2 << 8) | cp[1];
+                hash2 = (hash2 << 8) | cp[2];
+                hash2 = (hash2 << 8) | cp[3];
 #if __POINTER_SIZE__ == 8
-		hash2 = (hash2 << 8) | cp[4];
-		hash2 = (hash2 << 8) | cp[5];
-		hash2 = (hash2 << 8) | cp[6];
-		hash2 = (hash2 << 8) | cp[7];
+                hash2 = (hash2 << 8) | cp[4];
+                hash2 = (hash2 << 8) | cp[5];
+                hash2 = (hash2 << 8) | cp[6];
+                hash2 = (hash2 << 8) | cp[7];
 #endif
-		/*
-		 * multiply by large prime to scramble bits and
-		 * to avoid a 0 result from
-		 * #[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8.
-		 */
-		hash ^= (hash * 31415821) ^ hash2;
-	    }
-	    for (hash2 = 0; cp <= ep; cp++) {
-		hash2 = (hash2 << 8) | *cp;
-	    }
+                /*
+                 * multiply by large prime to scramble bits and
+                 * to avoid a 0 result from
+                 * #[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8.
+                 */
+                hash ^= (hash * 31415821) ^ hash2;
+            }
+            for (hash2 = 0; cp <= ep; cp++) {
+                hash2 = (hash2 << 8) | *cp;
+            }
 #endif
-	    hash ^= (hash * 31415821) ^ hash2;
-
-	    /*
-	     * fold the high bits not fitting into a SmallInteger
-	     */
-	    carry = hash & ~_MAX_INT;
-	    if (carry) {
-		hash = (hash & _MAX_INT) ^ (carry >> 8);
-	    }
-
-	    RETURN(__mkSmallInteger(hash));
-	}
+            hash ^= (hash * 31415821) ^ hash2;
+
+            /*
+             * fold the high bits not fitting into a SmallInteger
+             */
+            carry = hash & ~_MAX_INT;
+            if (carry) {
+                hash = (hash & _MAX_INT) ^ (carry >> 8);
+            }
+
+            RETURN(__mkSmallInteger(hash));
+        }
     }
 %}.
 
@@ -4202,14 +4202,14 @@
 
     first := true.
     1 to:self size do:[:idx |
-	aSeparatorStringOrCharacterOrNil notNil ifTrue:[
-	    first ifFalse:[
-		aSeparatorStringOrCharacterOrNil printOn:aStream
-	    ] ifTrue:[
-		first := false.
-	    ].
-	].
-	(self byteAt:idx) printOn:aStream base:16 size:2 fill:$0.
+        aSeparatorStringOrCharacterOrNil notNil ifTrue:[
+            first ifFalse:[
+                aSeparatorStringOrCharacterOrNil printOn:aStream
+            ] ifTrue:[
+                first := false.
+            ].
+        ].
+        (self byteAt:idx) printOn:aStream base:16 size:2 fill:$0.
     ].
 
     "
@@ -4238,9 +4238,9 @@
     "print as hex string, eg: 'FF:02:43'."
 
     ^ String
-	streamContents:[:s |
-	    self hexPrintOn:s withSeparator:aSeparatorStringOrCharacterOrNil.
-	]
+        streamContents:[:s |
+            self hexPrintOn:s withSeparator:aSeparatorStringOrCharacterOrNil.
+        ]
 
     "
       #[1 2 3 4 10 17] hexPrintStringWithSeparator:$:
@@ -4309,14 +4309,14 @@
 
 %{ /* NOCONTEXT */
     if (__mkSmallInteger(0) == __ClassInstPtr(__qClass(self))->c_ninstvars) {
-	/* I am only bytes */
-	RETURN(false)
+        /* I am only bytes */
+        RETURN(false)
     }
 %}.
     ^ super referencesAny:aCollection
 
     "
-	'abc' referencesAny:#()
+        'abc' referencesAny:#()
     "
 !