ByteArray.st
author Claus Gittinger <cg@exept.de>
Mon, 27 Jan 2020 13:47:24 +0100
changeset 25204 b12f8693fe6f
parent 24768 b83026fdb8cb
child 25210 672a4cdd0524
permissions -rw-r--r--
#BUGFIX by cg class: CharacterArray added: #asImmutableCollection #asImmutableString
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5425
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
    12
"{ Package: 'stx:libbasic' }"
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
    13
17377
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
    14
"{ NameSpace: Smalltalk }"
e4fdf84bd41a class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 16852
diff changeset
    15
3208
2d71538b9fd5 now subclass of UIBytes - which contains common protocol
Claus Gittinger <cg@exept.de>
parents: 3205
diff changeset
    16
UninterpretedBytes variableByteSubclass:#ByteArray
1002
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    17
	instanceVariableNames:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    18
	classVariableNames:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    19
	poolDictionaries:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    20
	category:'Collections-Arrayed'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
24768
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    23
!ByteArray class methodsFor:'documentation'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    24
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    25
copyright
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    26
"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    27
 COPYRIGHT (c) 1989 by Claus Gittinger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    28
	      All Rights Reserved
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    29
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    30
 This software is furnished under a license and may be used
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    31
 only in accordance with the terms of that license and with the
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    33
 be provided or otherwise made available to, or used by, any
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    34
 other person.  No title to or ownership of the software is
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    35
 hereby transferred.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    36
"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    37
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    38
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    39
documentation
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    40
"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    41
    ByteArrays store integers in the range 0..255.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    42
    In contrast to normal arrays (which store pointers to their elements),
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    43
    byteArrays store the values in a dense & compact way. 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    44
    ByteArrays can be used to hold the data for bitmaps, images and other bulk data
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    45
    (instances are returned eg. when reading a binary file or socket).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    46
    ByteArrays are also used to store the bytecode-instructions of an
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    47
    interpreted method and are used as superclass for Strings.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    48
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    49
    ByteArrays can be used as literals i.e. you can enter ByteArray-constants
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    50
    as #[ element1 element2 .... elementN] and also use byteArray constants
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    51
    as elements in a constant array.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    52
    As in: #( #[1 1 1] #[2 2 2] #[3 3 3])
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    53
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    54
    If you have to communicate structure-data (in the C-sense) with external
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    55
    programs/data-bases, see companion classes (Structure, ExternalBytes and ExternalStructure).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    56
    It allows the definition of subclasses of ByteArray, which transparently fetch
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    57
    and store C-structure fields.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    58
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    59
    [memory requirements:]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    60
        OBJ-HEADER + size
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    61
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    62
    [warning:]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    63
        read the warning about 'growing fixed size collection'
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    64
        in ArrayedCollection's documentation
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    65
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    66
    [author:]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    67
        Claus Gittinger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    68
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    69
    [See also:]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    70
        Array CharacterArray String
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    71
"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    72
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    73
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    74
!ByteArray class methodsFor:'instance creation'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    75
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    76
uninitializedNew:anInteger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    77
    "return a new instance of the receiver with uninitialized
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    78
     (i.e. undefined) contents. The indexed elements have any random
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    79
     value. However, any named instance variables are still nilled.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    80
     For use, when contents will be set anyway shortly after - this
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    81
     is a bit faster than the regular basicNew:, which clears the bytes.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    82
     Of course, it only makes a difference for very big ByteArrays, such
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    83
     as used for images/bitmaps.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    84
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    85
     Notice: if you want to port code using uninitializedNew: to another
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    86
     smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    87
     method to the ByteArray class of the other smalltalk."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    88
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    89
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    90
    OBJ newobj;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    91
    INT instsize, nInstVars, nindexedinstvars;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    92
    REGISTER OBJ *op;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    93
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    94
    if (__isSmallInteger(anInteger)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    95
	nindexedinstvars = __intVal(anInteger);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    96
	if (nindexedinstvars >= 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    97
	    if (self == ByteArray) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    98
		/*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
    99
		 * the most common case
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   100
		 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   101
		instsize = OHDR_SIZE + nindexedinstvars;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   102
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   103
		    __qCheckedNew(newobj, instsize);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   104
		    __InstPtr(newobj)->o_class = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   105
		    __qSTORE(newobj, self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   106
		    RETURN (newobj );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   107
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   108
	    } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   109
		/*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   110
		 * Take care for subclasses like TwoByteString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   111
		 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   112
		switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   113
		case BYTEARRAY:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   114
		    break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   115
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   116
		case WORDARRAY:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   117
		case SWORDARRAY:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   118
		    nindexedinstvars *= 2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   119
		    break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   120
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   121
		case LONGARRAY:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   122
		case SLONGARRAY:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   123
		    nindexedinstvars *= 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   124
		    break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   125
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   126
		default:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   127
		    /* don't know about this array type, delegate to super */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   128
		    goto out;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   129
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   130
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   131
	    nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   132
	    instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   133
	    __PROTECT_CONTEXT__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   134
	    __qNew(newobj, instsize);   /* OBJECT ALLOCATION */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   135
	    __UNPROTECT_CONTEXT__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   136
	    if (newobj != nil) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   137
		__InstPtr(newobj)->o_class = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   138
		__qSTORE(newobj, self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   139
		if (nInstVars) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   140
		    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   141
		     * still have to nil out named instvars ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   142
		     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   143
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   144
		    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   145
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   146
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   147
		    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   148
		     * knowing that nil is 0
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   149
		     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   150
		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   151
# else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   152
		    op = __InstPtr(newobj)->i_instvars;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   153
		    while (nInstVars--)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   154
			*op++ = nil;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   155
# endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   156
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   157
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   158
		RETURN ( newobj );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   159
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   160
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   161
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   162
out:;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   163
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   164
    ^ self basicNew:anInteger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   165
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   166
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   167
!ByteArray class methodsFor:'accessing'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   168
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   169
javaName
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   170
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   171
    ^'[B'.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   172
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   173
    "Modified: / 25-02-2011 / 19:02:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   174
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   175
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   176
!ByteArray class methodsFor:'accessing-java'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   177
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   178
javaArrayClass
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   179
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   180
    ^JavaArray javaArrayClassFor: self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   181
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   182
    "Created: / 11-06-2011 / 23:42:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   183
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   184
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   185
javaComponentClass
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   186
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   187
    ^JavaByte
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   188
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   189
    "Created: / 20-12-2010 / 22:05:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   190
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   191
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   192
!ByteArray class methodsFor:'binary storage'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   193
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   194
binaryDefinitionFrom: stream manager: manager
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   195
    "get a ByteArray from the binary stream.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   196
     ByteArrays are stored as a 4-byte int containing the size, 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   197
     followed by the actual bytes.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   198
     This is only invoked for long bytearrays.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   199
     Short ones are stored in a dense format with a 1 byte length."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   200
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   201
    |len|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   202
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   203
    "take care of subclasses ..."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   204
    self == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   205
        len := stream nextUnsignedInt32MSB:true.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   206
        ^ stream nextBytes:len.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   207
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   208
    ^ super binaryDefinitionFrom:stream manager:manager
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   209
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   210
    "Modified: / 2.11.1997 / 16:19:49 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   211
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   212
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   213
!ByteArray class methodsFor:'odbc queries'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   214
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   215
odbcTypeSymbol
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   216
    ^ #'SQL_BINARY'
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   217
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   218
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   219
!ByteArray class methodsFor:'queries'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   220
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   221
elementByteSize
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   222
    "for bit-like containers, return the number of bytes stored per element.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   223
     Here, 1 is returned"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   224
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   225
    ^ 1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   226
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   227
    "Created: / 15-09-2011 / 14:12:53 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   228
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   229
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   230
isBuiltInClass
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   231
    "return true if this class is known by the run-time-system.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   232
     Here, true is returned for myself, false for subclasses."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   233
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   234
    ^ self == ByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   235
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   236
    "Modified: 23.4.1996 / 15:56:25 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   237
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   238
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   239
isJavaArrayClass
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   240
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   241
    ^true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   242
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   243
    "Created: / 05-02-2011 / 22:45:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   244
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   245
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   246
isJavaReferenceType
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   247
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   248
    "Java arrays are reference types"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   249
    ^true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   250
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   251
    "Created: / 20-12-2010 / 22:30:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   252
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   253
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   254
maxVal
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   255
    "the minimum value which can be stored in instances of me.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   256
     For ByteArrays, this is 255"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   257
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   258
    ^ 255
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   259
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   260
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   261
minVal
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   262
    "the minimum value which can be stored in instances of me.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   263
     For ByteArrays, this is 0"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   264
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   265
    ^ 0
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   266
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   267
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   268
!ByteArray class methodsFor:'spray'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   269
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   270
sprayTypeName
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   271
	#swAdded.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   272
	^SOAP::XePName xsd: 'base64Binary'
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   273
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   274
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   275
!ByteArray class methodsFor:'testing'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   276
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   277
isInterface
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   278
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   279
    ^false
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   280
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   281
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   282
!ByteArray methodsFor:'Compatibility-Squeak'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   283
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   284
bitXor:aByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   285
    "return a new byteArray containing the bitWise-xor of the receiver's and the
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   286
     argument's bytes"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   287
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   288
    |size size1|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   289
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   290
    "size := self size min:aByteArray size"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   291
    size := self size.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   292
    size1 := aByteArray size.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   293
    size1 < size ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   294
        size := size1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   295
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   296
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   297
    ^ self copy
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   298
        bitXorBytesFrom:1 to:size with:aByteArray startingAt:1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   299
        yourself.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   300
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   301
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   302
     #[0 1 2 3 4] bitXor:#[0 1 2 3 4]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   303
     #[0 1 2 3 4] bitXor:#[0 1 2 3]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   304
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   305
! !
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   306
24743
3199983039fd #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24660
diff changeset
   307
!ByteArray methodsFor:'Compatibility-VW'!
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   308
24743
3199983039fd #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24660
diff changeset
   309
asByteString
3199983039fd #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24660
diff changeset
   310
    "same as asString, for visualworks compatibility"
3199983039fd #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24660
diff changeset
   311
    
3199983039fd #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24660
diff changeset
   312
    ^ self asString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   313
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   314
24768
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   315
!ByteArray methodsFor:'accessing'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   316
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   317
basicAt:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   318
    "return the indexed instance variable with index, anInteger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   319
     - redefined here to be slighly faster than the default in Object.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   320
     Q: is it worth the extra code ?"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   321
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   322
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   323
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   324
    REGISTER int indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   325
    REGISTER OBJ slf;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   326
    REGISTER OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   327
    REGISTER int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   328
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   329
    if (__isSmallInteger(index)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   330
	indx = __intVal(index) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   331
	slf = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   332
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   333
	    if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   334
		!= __MASKSMALLINT(BYTEARRAY)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   335
		goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   336
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   337
	    if (indx < 0) goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   338
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   339
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   340
	nIndex = __byteArraySize(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   341
	if ((unsigned)indx < (unsigned)nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   342
	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   343
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   344
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   345
  fail: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   346
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   347
    ^ super basicAt:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   348
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   349
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   350
basicAt:index put:value
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   351
    "set the indexed instance variable with index, anInteger to value.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   352
     Returns value (sigh).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   353
     - redefined here to be slighly faster than the default in Object.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   354
     Q: is it worth the extra code ?"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   355
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   356
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   357
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   358
    REGISTER int indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   359
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   360
    int val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   361
    REGISTER OBJ slf;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   362
    REGISTER OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   363
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   364
    if (__bothSmallInteger(index, value)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   365
	val = __intVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   366
	if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   367
	    indx = __intVal(index) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   368
	    slf = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   369
	    if ((cls = __qClass(slf)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   370
		if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   371
		    != __MASKSMALLINT(BYTEARRAY)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   372
		    goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   373
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   374
		if (indx < 0) goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   375
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   376
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   377
	    nIndex = __byteArraySize(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   378
	    if ((unsigned)indx < (unsigned)nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   379
		__ByteArrayInstPtr(slf)->ba_element[indx] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   380
		RETURN ( value );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   381
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   382
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   383
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   384
  fail: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   385
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   386
    ^ super basicAt:index put:value
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   387
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   388
    "Modified: 19.4.1996 / 11:14:40 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   389
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   390
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   391
bitAt:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   392
    "return the bit at index (1 based index) as 0 or 1"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   393
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   394
    |byteIndex bitIndex0 byte|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   395
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   396
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   397
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   398
    REGISTER int indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   399
    REGISTER int byte;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   400
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   401
    REGISTER OBJ slf;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   402
    REGISTER OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   403
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   404
    if (__isSmallInteger(index)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   405
	indx = __intVal(index) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   406
	slf = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   407
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   408
	byte = indx / 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   409
	indx = indx % 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   410
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   411
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   412
	    if (indx < 0) goto badIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   413
	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   414
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   415
	nIndex = __byteArraySize(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   416
	if ((unsigned)byte < (unsigned)nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   417
	    RETURN ( __mkSmallInteger(((__ByteArrayInstPtr(slf)->ba_element[byte] & (1 << indx)) != 0)) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   418
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   419
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   420
badIndex: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   421
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   422
    byteIndex := ((index-1) // 8) + 1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   423
    bitIndex0 := ((index-1) \\ 8).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   424
    byte := self at:byteIndex.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   425
    ^  byte bitTest:(1 bitShift:bitIndex0).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   426
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   427
   "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   428
     #[ 1 1 1 1 ] bitAt:9
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   429
     #[ 1 1 1 1 ] bitAt:11
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   430
     #[ 2 2 2 2 ] bitAt:10
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   431
   "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   432
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   433
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   434
bitClearAt:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   435
    "clear the bit at index (index starts with 1)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   436
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   437
    |byteIndex bitIndex0 byte|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   438
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   439
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   440
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   441
    REGISTER int indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   442
    REGISTER int byte;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   443
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   444
    REGISTER OBJ slf;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   445
    REGISTER OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   446
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   447
    if (0 /* __isSmallInteger(index) */) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   448
	indx = __intVal(index) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   449
	slf = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   450
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   451
	byte = indx / 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   452
	indx = indx % 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   453
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   454
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   455
	    if (indx < 0) goto badIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   456
	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   457
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   458
	nIndex = __byteArraySize(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   459
	if ((unsigned)byte < (unsigned)nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   460
	    __ByteArrayInstPtr(slf)->ba_element[byte] &= ~(1 << indx);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   461
	    RETURN (slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   462
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   463
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   464
badIndex: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   465
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   466
    byteIndex := ((index-1) // 8) + 1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   467
    bitIndex0 := ((index-1) \\ 8).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   468
    byte := self at:byteIndex.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   469
    byte := byte bitClear:(1 bitShift:bitIndex0).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   470
    self at:byteIndex put:byte.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   471
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   472
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   473
     #[0 0 0 0] copy bitClearAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   474
     #[0 0 0 0] copy bitClearAt:7
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   475
     #[0 0 0 0] copy bitClearAt:8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   476
     #[0 0 0 0] copy bitClearAt:9
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   477
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   478
   "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   479
     #[ 0 0 0 0 ] bitSetAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   480
     #[ 0 0 0 0 ] bitSetAt:4
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   481
     #[ 0 0 0 0 ] bitSetAt:8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   482
     #[ 0 0 0 0 ] bitSetAt:9
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   483
     #[ 0 0 0 0 ] bitSetAt:10
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   484
     #[ 0 0 0 0 ] bitSetAt:11
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   485
   "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   486
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   487
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   488
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   489
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   490
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   491
bitSetAt:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   492
    "set the bit at index (index starts with 1)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   493
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   494
    |byteIndex bitIndex0 byte|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   495
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   496
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   497
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   498
    if (__isSmallInteger(index)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   499
     && (__qClass(self) == @global(ByteArray))) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   500
        int indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   501
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   502
        indx = __intVal(index) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   503
        if (indx >= 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   504
            int byteIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   505
            int bitIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   506
            int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   507
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   508
            byteIndex = indx / 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   509
            bitIndex = indx % 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   510
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   511
            nIndex = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   512
            if ((unsigned)byteIndex < (unsigned)nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   513
                __ByteArrayInstPtr(self)->ba_element[byteIndex] |= (1 << bitIndex);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   514
                RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   515
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   516
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   517
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   518
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   519
    byteIndex := ((index-1) // 8) + 1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   520
    bitIndex0 := ((index-1) \\ 8).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   521
    byte := self at:byteIndex.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   522
    byte := byte bitOr:(1 bitShift:bitIndex0).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   523
    self at:byteIndex put:byte.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   524
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   525
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   526
     #[0 0 0 0] copy bitSetAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   527
     #[0 0 0 0] copy bitSetAt:7
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   528
     #[0 0 0 0] copy bitSetAt:8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   529
     #[0 0 0 0] copy bitSetAt:9
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   530
     #[0 0 0 0] copy bitSetAt:32
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   531
     #[0 0 0 0] copy bitSetAt:33
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   532
     #[0 0 0 0] copy bitSetAt:0
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   533
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   534
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   535
     #[ 0 0 0 0 ] bitSetAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   536
     #[ 0 0 0 0 ] bitSetAt:4
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   537
     #[ 0 0 0 0 ] bitSetAt:8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   538
     #[ 0 0 0 0 ] bitSetAt:9
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   539
     #[ 0 0 0 0 ] bitSetAt:10
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   540
     #[ 0 0 0 0 ] bitSetAt:11
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   541
   "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   542
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   543
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   544
!ByteArray methodsFor:'accessing-bytes'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   545
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   546
byteAt:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   547
    "return the byte at index.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   548
     For ByteArray, this is the same as basicAt:;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   549
     however, for strings or symbols, this returns a numeric byteValue
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   550
     instead of a character."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   551
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   552
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   553
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   554
    REGISTER int indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   555
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   556
    REGISTER OBJ slf;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   557
    REGISTER OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   558
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   559
    if (__isSmallInteger(index)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   560
	indx = __intVal(index) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   561
	slf = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   562
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   563
	    if (indx < 0) goto badIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   564
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   565
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   566
	nIndex = __byteArraySize(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   567
	if ((unsigned)indx < (unsigned)nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   568
	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   569
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   570
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   571
badIndex: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   572
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   573
    ^ (super basicAt:index) asInteger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   574
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   575
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   576
byteAt:index put:value
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   577
    "set the byte at index. For ByteArray, this is the same as basicAt:put:.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   578
     However, for Strings, this expects a byteValue to be stored."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   579
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   580
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   581
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   582
    REGISTER int indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   583
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   584
    int val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   585
    REGISTER OBJ slf;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   586
    REGISTER OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   587
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   588
    if (__bothSmallInteger(index, value)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   589
        val = __intVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   590
        if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   591
            indx = __intVal(index) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   592
            slf = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   593
            if ((cls = __qClass(slf)) != ByteArray) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   594
                if (indx < 0) goto badIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   595
                if (cls == ImmutableByteArray) goto badIndex; 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   596
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   597
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   598
            nIndex = __byteArraySize(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   599
            if ((unsigned)indx < (unsigned)nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   600
                __ByteArrayInstPtr(slf)->ba_element[indx] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   601
                RETURN ( value );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   602
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   603
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   604
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   605
badIndex: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   606
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   607
    ^ super basicAt:index put:value
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   608
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   609
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   610
!ByteArray methodsFor:'accessing-longs'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   611
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   612
unsignedInt32At:index put:value
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   613
    "set the 4-bytes starting at index from the (unsigned) Integer value.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   614
     The value should be in the range 0 to 16rFFFFFFFF
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   615
     (for negative values, the stored value is not defined).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   616
     The value is stored in the machine's natural byte order.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   617
     Q: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   618
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   619
    |t|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   620
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   621
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   622
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   623
    REGISTER INT indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   624
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   625
    union {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   626
        unsigned char u_char[4];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   627
        unsigned int u_uint;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   628
    } val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   629
    OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   630
    unsigned char *byteP;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   631
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   632
    if (__isSmallInteger(index)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   633
        if (__isSmallInteger(value)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   634
            val.u_uint = __intVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   635
        } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   636
            val.u_uint = __longIntVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   637
            if (val.u_uint == 0) goto error;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   638
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   639
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   640
        indx = __intVal(index);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   641
        if (indx > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   642
            if ((cls = __qClass(self)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   643
                if (cls == ImmutableByteArray) goto error;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   644
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   645
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   646
            nIndex = __qSize(self) - OHDR_SIZE;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   647
            if ((indx+3) <= nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   648
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   649
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   650
                ((unsigned int *)byteP)[0] = val.u_uint;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   651
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   652
                if (((unsigned INT)byteP & 3) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   653
                    ((unsigned int *)byteP)[0] = val.u_uint;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   654
                } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   655
                    byteP[0] = val.u_char[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   656
                    byteP[1] = val.u_char[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   657
                    byteP[2] = val.u_char[2];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   658
                    byteP[3] = val.u_char[3];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   659
                }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   660
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   661
                RETURN ( value );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   662
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   663
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   664
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   665
  error: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   666
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   667
    ^ super unsignedInt32At:index put:value.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   668
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   669
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   670
     |b|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   671
     b := ByteArray new:4.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   672
     b unsignedInt32At:1 put:16r04030201.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   673
     b inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   674
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   675
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   676
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   677
unsignedInt32At:index put:value MSB:msb
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   678
    "set the 4-bytes starting at index from the (unsigned) Integer value.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   679
     The value must be in the range 0 to 16rFFFFFFFF.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   680
     The value is stored MSB-first if msb is true; LSB-first otherwise.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   681
     question: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   682
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   683
    |t|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   684
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   685
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   686
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   687
    REGISTER INT indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   688
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   689
    int val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   690
    OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   691
    unsigned char *byteP;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   692
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   693
    if (__isSmallInteger(index)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   694
        if (__isSmallInteger(value)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   695
            val = __intVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   696
        } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   697
            val = __longIntVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   698
            if (val == 0) goto error;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   699
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   700
        indx = __intVal(index);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   701
        if (indx > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   702
            if ((cls = __qClass(self)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   703
                if (cls == ImmutableByteArray) goto error;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   704
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   705
            }        
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   706
            nIndex = __qSize(self) - OHDR_SIZE;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   707
            if ((indx+3) <= nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   708
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   709
                if (msb == true) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   710
                    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   711
                     * most significant byte first (i.e sparc order)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   712
                     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   713
#if defined(__MSBFIRST__)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   714
                    if (((INT)byteP & 3) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   715
                        ((int *)byteP)[0] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   716
                    } else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   717
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   718
                    {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   719
                        byteP[3] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   720
                        val >>= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   721
                        byteP[2] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   722
                        val >>= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   723
                        byteP[1] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   724
                        val >>= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   725
                        byteP[0] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   726
                    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   727
                } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   728
                    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   729
                     * least significant byte first (i.e i386/alpha order)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   730
                     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   731
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   732
                    ((int *)byteP)[0] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   733
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   734
# if defined(__LSBFIRST__)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   735
                    if (((unsigned INT)byteP & 3) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   736
                        ((int *)byteP)[0] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   737
                    } else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   738
# endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   739
                    {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   740
                        byteP[0] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   741
                        val >>= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   742
                        byteP[1] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   743
                        val >>= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   744
                        byteP[2] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   745
                        val >>= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   746
                        byteP[3] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   747
                    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   748
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   749
                }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   750
                RETURN ( value );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   751
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   752
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   753
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   754
  error: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   755
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   756
    ^ super unsignedInt32At:index put:value MSB:msb
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   757
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   758
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   759
     |b|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   760
     b := ByteArray new:8.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   761
     b unsignedInt32At:1 put:16r04030201 MSB:true.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   762
     b unsignedInt32At:5 put:16r04030201 MSB:false.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   763
     b inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   764
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   765
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   766
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   767
!ByteArray methodsFor:'accessing-shorts'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   768
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   769
unsignedInt16At:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   770
    "return the 2-bytes starting at index as an (unsigned) Integer.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   771
     The value is retrieved in the machine's natural byte order
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   772
     Notice: 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   773
        the index is a byte index; thus, this allows for unaligned access to
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   774
        words on any boundary.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   775
     Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   776
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   777
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   778
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   779
    REGISTER INT indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   780
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   781
    union {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   782
        unsigned char u_char[2];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   783
        unsigned short u_ushort;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   784
    } val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   785
    unsigned char *byteP;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   786
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   787
    if (__isSmallInteger(index)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   788
        indx = __intVal(index);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   789
        if (indx > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   790
            if (!__isByteArrayLike(self))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   791
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   792
            nIndex = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   793
            if ((indx+1) <= nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   794
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   795
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   796
                val.u_ushort = ((unsigned short *)byteP)[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   797
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   798
                val.u_char[0] = byteP[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   799
                val.u_char[1] = byteP[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   800
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   801
                RETURN ( __mkSmallInteger((val.u_ushort)) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   802
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   803
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   804
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   805
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   806
    ^ super unsignedInt16At:index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   807
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   808
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   809
unsignedInt16At:index MSB:msb
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   810
    "return the 2-bytes starting at index as an (unsigned) Integer.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   811
     The value is retrieved MSB (high 8 bits at lower index) if msb is true;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   812
     LSB-first (i.e. low 8-bits at lower byte index) if it's false.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   813
     Notice: 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   814
        the index is a byte index; thus, this allows for unaligned access to
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   815
        words on any boundary.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   816
     Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   817
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   818
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   819
    REGISTER INT indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   820
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   821
    int val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   822
    unsigned char *byteP;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   823
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   824
    if (__isSmallInteger(index)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   825
        indx = __intVal(index);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   826
        if (indx > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   827
            if (!__isByteArrayLike(self))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   828
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   829
            nIndex = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   830
            if ((indx+1) <= nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   831
                byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   832
                if (msb == true) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   833
                    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   834
                     * most significant byte first (i.e sparc order)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   835
                     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   836
#if defined(__MSBFIRST__)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   837
                    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   838
                     * mhmh to be measured:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   839
                     *   the if may hurt more than the additional
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   840
                     *   memory cycles on some machines ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   841
                     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   842
                    if (((INT)byteP & 1) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   843
                        /* aligned */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   844
                        val = ((unsigned short *)byteP)[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   845
                    } else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   846
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   847
                    {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   848
                        val = byteP[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   849
                        val = (val << 8) + byteP[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   850
                    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   851
                } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   852
                    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   853
                     * least significant byte first (i.e i386/alpha order)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   854
                     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   855
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   856
                    val = ((unsigned short *)byteP)[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   857
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   858
# if defined(__LSBFIRST__)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   859
                    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   860
                     * mhmh to be measured:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   861
                     *   the if may hurt more than the additional
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   862
                     *   memory cycles on some machines ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   863
                     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   864
                    if (((INT)byteP & 1) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   865
                        /* aligned */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   866
                        val = ((unsigned short *)byteP)[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   867
                    } else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   868
# endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   869
                    {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   870
                        val = byteP[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   871
                        val = (val << 8) + byteP[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   872
                    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   873
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   874
                }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   875
                RETURN ( __mkSmallInteger(val) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   876
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   877
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   878
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   879
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   880
    ^ super unsignedInt16At:index MSB:msb
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   881
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   882
    "Modified (comment): / 13-02-2017 / 19:56:53 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   883
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   884
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   885
unsignedInt16At:index put:value
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   886
    "set the 2-bytes starting at index from the (unsigned) Integer value.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   887
     The stored value must be in the range 0 .. 16rFFFF.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   888
     The value is stored in the machine's natural byteorder,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   889
     i.e. this method should only be used to fill byteArrays which are
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   890
     used internally (not passed to other machines).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   891
     Notice: 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   892
        the index is a byte index; thus, this allows for unaligned access to
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   893
        words on any boundary.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   894
     Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   895
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   896
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   897
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   898
    REGISTER INT indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   899
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   900
    int v;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   901
    union {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   902
        unsigned char u_char[2];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   903
        unsigned short u_ushort;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   904
    } val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   905
    unsigned char *byteP;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   906
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   907
    if (__bothSmallInteger(index, value)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   908
        indx = __intVal(index);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   909
        if (indx > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   910
            if (!__isByteArray(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   911
                OBJ cls = __qClass(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   912
                if (cls == ImmutableByteArray) goto immutable;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   913
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   914
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   915
            nIndex = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   916
            if ((indx+1) <= nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   917
                v = __intVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   918
                if ((v & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   919
                    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   920
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   921
                    ((unsigned short *)byteP)[0] = v;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   922
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   923
                    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   924
                     * mhmh to be measured:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   925
                     *   the if may hurt more than the additional
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   926
                     *   memory cycles on some machines ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   927
                     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   928
                    if (((INT)byteP & 1) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   929
                        /* aligned */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   930
                        ((unsigned short *)byteP)[0] = v;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   931
                    } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   932
                        val.u_ushort = v;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   933
                        byteP[0] = val.u_char[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   934
                        byteP[1] = val.u_char[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   935
                    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   936
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   937
                    RETURN ( value );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   938
                }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   939
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   940
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   941
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   942
immutable: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   943
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   944
    ^ self unsignedInt16At:index put:value MSB:IsBigEndian
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   945
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   946
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   947
     |b|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   948
     b := ByteArray new:4.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   949
     b unsignedInt16At:1 put:16r0102.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   950
     b unsignedInt16At:3 put:16r0304.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   951
     b inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   952
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   953
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   954
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   955
unsignedInt16At:index put:value MSB:msb
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   956
    "set the 2-bytes starting at index from the (unsigned) Integer value.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   957
     The stored value must be in the range 0 .. 16rFFFF.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   958
     The value is stored LSB-first (i.e. the low 8bits are stored at the
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   959
     lower index) if msb is false, MSB-first otherwise.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   960
     Notice: 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   961
        the index is a byte index; thus, this allows for unaligned access to
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   962
        words on any boundary.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   963
     Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   964
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   965
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   966
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   967
    REGISTER INT indx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   968
    int nIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   969
    int val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   970
    OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   971
    unsigned char *byteP;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   972
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   973
    if (__bothSmallInteger(index, value)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   974
        indx = __intVal(index);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   975
        if (indx > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   976
            if (!__isByteArray(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   977
                OBJ cls = __qClass(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   978
                if (cls == ImmutableByteArray) goto immutable;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   979
                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   980
            }        
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   981
            nIndex = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   982
            if ((indx+1) <= nIndex) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   983
                val = __intVal(value);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   984
                if ((val & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   985
                    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   986
                    if (msb == true) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   987
                        /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   988
                         * most significant byte first (i.e sparc order)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   989
                         */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   990
#if defined(__MSBFIRST__)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   991
                        /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   992
                         * mhmh to be measured:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   993
                         *   the if may hurt more than the additional
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   994
                         *   memory cycles on some machines ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   995
                         */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   996
                        if (((INT)byteP & 1) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   997
                            /* aligned */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   998
                            ((unsigned short *)byteP)[0] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
   999
                        } else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1000
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1001
                        {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1002
                            byteP[1] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1003
                            byteP[0] = (val>>8) & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1004
                        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1005
                    } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1006
                        /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1007
                         * least significant byte first (i.e i386/alpha order)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1008
                         */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1009
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1010
                        ((unsigned short *)byteP)[0] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1011
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1012
# if defined(__LSBFIRST__)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1013
                        /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1014
                         * mhmh to be measured:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1015
                         *   the if may hurt more than the additional
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1016
                         *   memory cycles on some machines ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1017
                         */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1018
                        if (((INT)byteP & 1) == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1019
                            /* aligned */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1020
                            ((unsigned short *)byteP)[0] = val;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1021
                        } else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1022
# endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1023
                        {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1024
                            byteP[0] = val & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1025
                            byteP[1] = (val>>8) & 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1026
                        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1027
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1028
                    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1029
                    RETURN ( value );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1030
                }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1031
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1032
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1033
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1034
immutable: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1035
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1036
    ^ super unsignedInt16At:index put:value MSB:msb
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1037
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1038
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1039
     |b|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1040
     b := ByteArray new:8.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1041
     b unsignedInt16At:1 put:16r0102 MSB:false.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1042
     b unsignedInt16At:3 put:16r0304 MSB:false.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1043
     b unsignedInt16At:5 put:16r0102 MSB:true.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1044
     b unsignedInt16At:7 put:16r0304 MSB:true.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1045
     b inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1046
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1047
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1048
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1049
!ByteArray methodsFor:'binary storage'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1050
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1051
storeBinaryDefinitionOn:stream manager:manager
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1052
    "append a binary representation of the receiver onto stream.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1053
     Redefined since short ByteArrays can be stored with a special type code
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1054
     in a more compact way.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1055
     This is an internal interface for the binary storage mechanism."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1056
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1057
    |myClass myBasicSize|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1058
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1059
    "not, if I have named instance variables"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1060
    (myClass := self class) instSize ~~ 0 ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1061
        ^ super storeBinaryDefinitionOn:stream manager:manager
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1062
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1063
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1064
    myBasicSize := self basicSize.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1065
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1066
    "/ can use a more compact representation;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1067
    "/ but not for subclasses ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1068
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1069
    ((myClass == ByteArray)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1070
    and:[myBasicSize <= 255]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1071
        "/ special encoding: <codeForByteArray> <len> <bytes> ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1072
        stream nextPut:(manager codeForByteArray); nextPut:myBasicSize.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1073
    ] ifFalse:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1074
        manager putIdOfClass:myClass on:stream.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1075
        stream nextNumber:4 put:myBasicSize MSB:true.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1076
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1077
    self storeBinaryElementsOn:stream.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1078
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1079
    "Modified: / 2.11.1997 / 15:28:45 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1080
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1081
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1082
storeBinaryElementsOn:aStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1083
    aStream nextPutBytes:self basicSize from:self startingAt:1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1084
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1085
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1086
!ByteArray methodsFor:'comparing'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1087
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1088
= aByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1089
    "Compare the receiver with the argument and return true if the
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1090
     receiver is equal to the argument (i.e. has the same size and elements).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1091
     Otherwise return false."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1092
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1093
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1094
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1095
    int l1, l2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1096
    REGISTER OBJ s = aByteArray;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1097
    unsigned char *cp1, *cp2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1098
    OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1099
    OBJ myCls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1100
    INT addrDelta;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1101
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1102
    if (s == self) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1103
	RETURN ( true );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1104
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1105
    if (! __isNonNilObject(s)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1106
	RETURN ( false );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1107
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1108
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1109
    cls = __qClass(s);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1110
    myCls = __qClass(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1111
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1112
    if (cls == myCls) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1113
	l2 = __byteArraySize(s);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1114
	l1 = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1115
	if (l1 != l2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1116
	    RETURN ( false );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1117
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1118
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1119
	cp1 = __byteArrayVal(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1120
	cp2 = __byteArrayVal(s);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1121
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1122
	/*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1123
	 * care for instances of subclasses ...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1124
	 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1125
	if (cls != ByteArray) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1126
	    int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1127
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1128
	    cp2 += n;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1129
	    cp1 += n;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1130
	    l1 -= n;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1131
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1132
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1133
	addrDelta = cp2 - cp1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1134
	while (l1 >= (sizeof(unsigned INT) * 4)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1135
	    if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1136
		RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1137
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1138
	    if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1139
		RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1140
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1141
	    if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1142
		RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1143
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1144
	    if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1145
		RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1146
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1147
	    l1 -= sizeof(unsigned INT)*4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1148
	    cp1 += sizeof(unsigned INT)*4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1149
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1150
	while (l1 >= sizeof(unsigned INT)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1151
	    if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1152
		RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1153
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1154
	    l1 -= sizeof(unsigned INT);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1155
	    cp1 += sizeof(unsigned INT);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1156
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1157
	if (l1 >= sizeof(unsigned short)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1158
	    if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1159
		RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1160
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1161
	    l1 -= sizeof(unsigned short);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1162
	    cp1 += sizeof(unsigned short);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1163
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1164
	while (l1) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1165
	    if (*cp1 != *(cp1+addrDelta)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1166
		RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1167
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1168
	    l1--;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1169
	    cp1++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1170
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1171
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1172
	RETURN (true);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1173
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1174
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1175
    ^ super = aByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1176
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1177
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1178
!ByteArray methodsFor:'converting'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1179
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1180
asByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1181
    "return the receiver as a byteArray"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1182
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1183
    "could be an instance of a subclass..."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1184
    self class == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1185
	^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1186
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1187
    ^ super asByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1188
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1189
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1190
     'hello world' asByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1191
     #(1 2 3 4 5 6 7) asByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1192
     #(1 2 256 4 5 6 7) asByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1193
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1194
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1195
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1196
asHGChangesetId
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1197
    ^ HGChangesetId fromBytes:self.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1198
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1199
    "Created: / 16-11-2012 / 21:33:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1200
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1201
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1202
asImmutableByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1203
    "return a write-protected copy of myself"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1204
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1205
    |copy|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1206
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1207
    copy := self copy.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1208
    copy class == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1209
        ^ copy changeClassTo:ImmutableByteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1210
    ] ifFalse:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1211
        ^ self shouldNotImplement.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1212
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1213
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1214
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1215
asImmutableCollection
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1216
    "return a write-protected copy of myself"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1217
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1218
    ^ self asImmutableByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1219
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1220
    "Created: / 15-03-2019 / 13:48:05 / Stefan Vogel"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1221
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1222
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1223
asInteger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1224
    "convert myself to an unsigned integer - the first byte is most significant.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1225
     This is also in Squeak."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1226
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1227
    ^ self asIntegerMSB:true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1228
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1229
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1230
        #[ 2 ] asInteger hexPrintString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1231
        #[ 16r1 16r2 ] asInteger hexPrintString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1232
        #[4 0 0 0 0 0 0 0] asInteger hexPrintString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1233
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1234
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1235
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1236
asIntegerMSB:isMSBFirst
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1237
    "convert myself to an unsigned integer - the first byte is most significant.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1238
     This is also in Squeak."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1239
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1240
    ^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1241
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1242
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1243
        (#[ 2 ] asIntegerMSB:true) hexPrintString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1244
        (#[ 16r1 16r2 ] asIntegerMSB:true) hexPrintString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1245
        (#[ 16r1 16r2 ] asIntegerMSB:false) hexPrintString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1246
        (#[4 0 0 0 0 0 0 0 0 0 0 0] asIntegerMSB:true) hexPrintString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1247
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1248
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1249
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1250
asPackedString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1251
    "ST-80 compatibility: encode the receiver into an ascii String
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1252
     with 6bits encoded per character. Each group of 6 bits is encoded
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1253
     as a corresponding character (32+value) and the resulting string
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1254
     is returned. The resulting string is always a multiple of 4 (since
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1255
     24 is the lcm of 6 and 8) and the number of remaining characters is
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1256
     encoded in the last character.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1257
     ST-80 uses this encoding for Images...
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1258
     This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1259
     PS: I don't like it ;-)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1260
     See also: fromPackedString: - the reverse operation"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1261
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1262
    |outStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1263
     index     "{ Class:SmallInteger}"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1264
     nextIndex "{ Class:SmallInteger}"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1265
     stop      "{ Class:SmallInteger}"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1266
     n         "{ Class:SmallInteger}"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1267
     mod       "{ Class:SmallInteger}"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1268
     cpl|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1269
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1270
    outStream := WriteStream on:(String new:((self size + 2) * 4 // 3)).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1271
    index := 1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1272
    stop := self size.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1273
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1274
    stop > 100 ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1275
	"/ cg:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1276
	"/ initial lineBreak
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1277
	outStream cr.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1278
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1279
    cpl := 0.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1280
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1281
    [index <= stop] whileTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1282
	"take 3 source bytes"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1283
	n := (self at:index) bitShift:16.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1284
	(index < stop) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1285
	    nextIndex := index + 1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1286
	    n := n bitOr:((self at:nextIndex) bitShift:8).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1287
	    (nextIndex < stop) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1288
		n := n bitOr:(self at:(index + 2)).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1289
	    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1290
	].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1291
	index := index + 3.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1292
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1293
	"took me a while to find that one out ..."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1294
	n := n bitXor:16r820820.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1295
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1296
	outStream nextPut:(Character value:((n bitShift:-18) bitAnd:16r3F) + 32).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1297
	outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1298
	outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1299
	outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1300
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1301
	"/ cg:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1302
	"/ lineBreak after every 120 characters
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1303
	"/ fromPackedString will ignore those
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1304
	cpl := cpl + 4.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1305
	cpl >= 120 ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1306
	    outStream cr.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1307
	    cpl := 0.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1308
	].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1309
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1310
    (mod := stop \\ 3) ~~ 0 ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1311
	outStream backStep.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1312
	outStream nextPut:(Character value:(mod + 96)).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1313
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1314
    ^ outStream contents
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1315
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1316
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1317
     #[ 16r00 16r01 16r02 16r04 16r08 16r10 16r20 16r40 16r80 ] asPackedString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1318
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1319
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1320
    "Modified: 12.11.1996 / 15:45:02 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1321
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1322
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1323
asSignedByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1324
    "return the receiver as a signed byteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1325
     elements > 127 are converted to negative numbers."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1326
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1327
    |cls|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1328
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1329
    cls := self class.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1330
    "could be an instance of a subclass..."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1331
    (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1332
        ^ self copy changeClassTo:SignedByteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1333
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1334
    ^ super asSignedByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1335
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1336
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1337
     'hello world' asSignedByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1338
     #[1 2 3 4 5 6 7] asSignedByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1339
     #[1 2 129 4 5 6 7] asSignedByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1340
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1341
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1342
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1343
asString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1344
    "speed up string conversions"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1345
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1346
    |size cls|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1347
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1348
    cls := self class.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1349
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1350
    (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1351
        size := self size.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1352
        ^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1353
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1354
    ^ super asString.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1355
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1356
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1357
      #[16r41 16r42 16r43] asString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1358
      #[16r41 16r42 16r43] asImmutableByteArray asString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1359
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1360
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1361
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1362
beImmutable
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1363
    "make myself write-protected"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1364
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1365
    super beImmutable.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1366
    self class == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1367
        self changeClassTo:ImmutableByteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1368
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1369
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1370
    "Modified: / 09-06-2019 / 15:14:59 / Claus Gittinger"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1371
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1372
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1373
beSigned
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1374
    "destructively make mayself signed.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1375
     elements > 127 are converted to negative numbers.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1376
     WARNING: this changes the receiver itself 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1377
     - use this only for initialization of new instances"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1378
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1379
    self class == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1380
        self changeClassTo:SignedByteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1381
    ] ifFalse:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1382
        self shouldNotImplement.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1383
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1384
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1385
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1386
     #[ 1 2 3 128 255 ] copy beSigned
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1387
     #[ 1 2 3 128 255 ] beImmutable beSigned
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1388
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1389
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1390
    "Modified: / 09-06-2019 / 14:57:56 / Claus Gittinger"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1391
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1392
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1393
beUnsigned
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1394
    "that's what I am (but I don't know if this is true for subclasses)."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1395
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1396
    self class == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1397
        ^ self.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1398
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1399
    self shouldNotImplement.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1400
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1401
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1402
     #[ 1 2 3 128 255 ] copy beUnsigned
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1403
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1404
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1405
    "Modified (comment): / 09-06-2019 / 14:58:22 / Claus Gittinger"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1406
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1407
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1408
decodeAsLiteralArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1409
    "given a literalEncoding in the receiver,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1410
     create & return the corresponding object.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1411
     The inverse operation to #literalArrayEncoding."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1412
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1413
    ^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1414
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1415
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1416
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1417
literalArrayEncoding
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1418
    "encode myself as an array literal, from which a copy of the receiver
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1419
     can be reconstructed with #decodeAsLiteralArray."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1420
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1421
    |cls|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1422
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1423
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1424
	^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1425
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1426
    ^ super literalArrayEncoding
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1427
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1428
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1429
     #[1 2 3] literalArrayEncoding
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1430
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1431
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1432
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1433
!ByteArray methodsFor:'copying'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1434
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1435
copy
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1436
    "redefined for a bit more speed"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1437
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1438
    self class == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1439
	^ self copyFrom:1 to:(self size)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1440
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1441
    ^ super copy
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1442
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1443
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1444
copyFrom:start to:stop
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1445
    "return the subcollection starting at index start, anInteger and ending
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1446
     at stop, anInteger.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1447
     - reimplemented here for speed"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1448
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1449
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1450
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1451
    REGISTER unsigned char *srcp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1452
    REGISTER unsigned char *dstp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1453
    REGISTER int count;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1454
    int len, index1, index2, sz;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1455
    OBJ newByteArray;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1456
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1457
    if (__isByteArrayLike(self)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1458
     && __bothSmallInteger(start, stop)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1459
	len = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1460
	index1 = __intVal(start);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1461
	index2 = __intVal(stop);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1462
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1463
	if ((index1 <= index2) && (index1 > 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1464
	    if (index2 <= len) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1465
		count = index2 - index1 + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1466
		__PROTECT_CONTEXT__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1467
		sz = OHDR_SIZE + count;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1468
		__qNew(newByteArray, sz);       /* OBJECT ALLOCATION */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1469
		__UNPROTECT_CONTEXT__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1470
		if (newByteArray != nil) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1471
		    __InstPtr(newByteArray)->o_class = ByteArray;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1472
		    __qSTORE(newByteArray, ByteArray);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1473
		    dstp = __ByteArrayInstPtr(newByteArray)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1474
		    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1475
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1476
#ifdef bcopy4
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1477
		    if (((unsigned INT)srcp & 3) == ((unsigned INT)dstp & 3)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1478
			int nW;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1479
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1480
			/* copy unaligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1481
			while (count && (((unsigned INT)srcp & 3) != 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1482
			    *dstp++ = *srcp++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1483
			    count--;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1484
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1485
			if (count) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1486
			    /* copy aligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1487
			    nW = count >> 2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1488
			    if (count & 3) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1489
				nW++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1490
			    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1491
			    bcopy4(srcp, dstp, nW);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1492
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1493
			RETURN ( newByteArray );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1494
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1495
#endif /* bcopy4 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1496
#if __POINTER_SIZE__ == 8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1497
		    if (((unsigned INT)srcp & 7) == ((unsigned INT)dstp & 7)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1498
			int nW;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1499
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1500
			/* copy unaligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1501
			while (count && (((unsigned INT)srcp & 7) != 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1502
			    *dstp++ = *srcp++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1503
			    count--;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1504
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1505
			/* copy aligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1506
			while (count >= 8) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1507
			    ((unsigned INT *)dstp)[0] = ((unsigned INT *)srcp)[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1508
			    dstp += 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1509
			    srcp += 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1510
			    count -= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1511
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1512
			/* copy remaining part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1513
			while (count) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1514
			    *dstp++ = *srcp++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1515
			    count--;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1516
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1517
			RETURN ( newByteArray );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1518
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1519
#endif /* bcopy4 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1520
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1521
#ifdef FAST_MEMCPY
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1522
		    bcopy(srcp, dstp, count);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1523
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1524
		    while (count--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1525
			*dstp++ = *srcp++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1526
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1527
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1528
		    RETURN ( newByteArray );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1529
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1530
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1531
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1532
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1533
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1534
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1535
     fall back in case of non-integer index or out-of-bound index;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1536
     will eventually lead to an out-of-bound signal raise
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1537
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1538
    ^ super copyFrom:start to:stop
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1539
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1540
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1541
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:1 to:10
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1542
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:7
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1543
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1544
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:11
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1545
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:10
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1546
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:9
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1547
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1548
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1549
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1550
shallowCopy
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1551
    "redefined for a bit more speed"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1552
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1553
    self class == ByteArray ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1554
	^ self copyFrom:1 to:(self size)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1555
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1556
    ^ super shallowCopy
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1557
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1558
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1559
symbolFrom:start to:stop
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1560
    "make a symbol from the characters of the subcollection starting
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1561
     at index start, anInteger and ending at stop, anInteger.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1562
     This saves us garbage and character copying."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1563
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1564
    |sym|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1565
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1566
%{  /* STACK:1024 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1567
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1568
    REGISTER unsigned char *srcp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1569
    REGISTER unsigned char *endp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1570
    REGISTER int count;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1571
    int len, index1, index2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1572
    unsigned char scratchBuffer[1024], savec;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1573
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1574
    if (__isByteArrayLike(self) && __bothSmallInteger(start, stop)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1575
	len = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1576
	index1 = __intVal(start);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1577
	index2 = __intVal(stop);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1578
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1579
	if ((index1 <= index2) && (index1 > 0) && (index2 <= len)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1580
	    count = index2 - index1 + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1581
	    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1582
	    if (index2 < len) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1583
		/* temporarily stuff in a '\0' */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1584
		endp = srcp + count + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1585
		savec = *endp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1586
		*endp = '\0';
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1587
		sym = __MKSYMBOL(srcp, 0);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1588
		/* must refetch endp (in case of a GC */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1589
		endp = __ByteArrayInstPtr(self)->ba_element + index1 + count;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1590
		*endp = savec;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1591
	    } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1592
		/* not enough space for '\0', copy the bytes */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1593
		if (count < sizeof(scratchBuffer)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1594
		    bcopy(srcp, scratchBuffer, count);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1595
		    scratchBuffer[count] = '\0';
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1596
		    sym = __MKSYMBOL(scratchBuffer, 0);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1597
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1598
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1599
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1600
	if (sym != nil)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1601
	    RETURN(sym);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1602
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1603
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1604
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1605
     fall back in case of non-integer index or out-of-bound index
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1606
     or not enough stack-memory available;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1607
     may eventually lead to an out-of-bound signal raise
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1608
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1609
    ^ (super copyFrom:start to:stop) asString asSymbol
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1610
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1611
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1612
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1613
     'abcdefghijklmnop' symbolFrom:1 to:3
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1614
     'abcdefghijklmnop' symbolFrom:3 to:16
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1615
     'abcdefghijklmnop' symbolFrom:3 to:17
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1616
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1617
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1618
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1619
!ByteArray methodsFor:'filling & replacing'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1620
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1621
from:start to:stop put:aNumber
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1622
    "fill part of the receiver with aNumber.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1623
     - reimplemented here for speed"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1624
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1625
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1626
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1627
    REGISTER unsigned char *dstp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1628
    REGISTER int count, value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1629
    int len, index1, index2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1630
    OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1631
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1632
    if (__isSmallInteger(aNumber)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1633
     && __bothSmallInteger(start, stop)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1634
     && __isBytes(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1635
	len = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1636
	index1 = __intVal(start);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1637
	index2 = __intVal(stop);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1638
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1639
	dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1640
	if ((cls = __qClass(self)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1641
	    int nInst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1642
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1643
	    nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1644
	    dstp += nInst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1645
	    len -= nInst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1646
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1647
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1648
	value = __intVal(aNumber);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1649
	if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1650
	 && (index1 <= index2)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1651
	 && (index1 > 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1652
	    if (index2 <= len) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1653
		count = index2 - index1 + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1654
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1655
#ifdef memset4
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1656
		if (count > 20) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1657
		    /* fill unaligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1658
		    while (((unsigned INT)dstp & 3) != 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1659
			*dstp++ = value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1660
			count--;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1661
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1662
		    /* fill aligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1663
		    {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1664
			int n4 = count & ~3;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1665
			int v4, nW;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1666
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1667
			v4 = (value << 8) | value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1668
			v4 = (v4 << 16) | v4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1669
			nW = n4>>2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1670
			memset4(dstp, v4, nW);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1671
			count -= n4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1672
			dstp += n4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1673
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1674
		    while (count--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1675
			*dstp++ = value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1676
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1677
		    RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1678
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1679
#endif /* memset4 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1680
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1681
#if (__POINTER_SIZE__ == 8)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1682
		{
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1683
		    INT v8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1684
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1685
		    v8 = (value << 8) | value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1686
		    v8 = (v8 << 16) | v8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1687
		    v8 = (v8 << 32) | v8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1688
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1689
		    /* fill unaligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1690
		    while ((count > 0) && (((unsigned INT)dstp & 3) != 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1691
			*dstp++ = value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1692
			count--;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1693
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1694
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1695
		    if ((count >= 4) && (((unsigned INT)dstp & 7) != 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1696
			((unsigned int *)dstp)[0] = v8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1697
			dstp += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1698
			count -= 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1699
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1700
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1701
		    /* fill aligned part */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1702
		    while (count >= 8) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1703
			((unsigned INT *)dstp)[0] = v8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1704
			dstp += 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1705
			count -= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1706
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1707
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1708
		    /* fill rest */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1709
		    if (count >= 4) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1710
			((unsigned int *)dstp)[0] = v8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1711
			dstp += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1712
			count -= 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1713
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1714
		    if (count >= 2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1715
			((unsigned short *)dstp)[0] = v8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1716
			dstp += 2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1717
			count -= 2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1718
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1719
		    if (count) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1720
			*dstp = value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1721
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1722
		    RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1723
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1724
#endif /* 64bit */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1725
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1726
#ifdef FAST_MEMSET
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1727
		memset(dstp, value, count);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1728
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1729
# ifdef __UNROLL_LOOPS__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1730
		while (count >= 8) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1731
		    dstp[0] = dstp[1] = dstp[2] = dstp[3] =
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1732
		    dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1733
		    dstp += 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1734
		    count -= 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1735
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1736
# endif /* __UNROLL_LOOPS__ */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1737
		while (count--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1738
		    *dstp++ = value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1739
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1740
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1741
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1742
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1743
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1744
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1745
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1746
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1747
     fall back in case of non-integer index or out-of-bound index/value;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1748
     will eventually lead to an out-of-bound signal raise
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1749
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1750
    ^ super from:start to:stop put:aNumber
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1751
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1752
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1753
     (ByteArray new:10) from:1 to:10 put:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1754
     (ByteArray new:20) from:10 to:20 put:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1755
     (ByteArray new:20) from:1 to:10 put:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1756
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1757
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1758
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1759
!ByteArray methodsFor:'image manipulation support'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1760
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1761
bitAndBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1762
    "replace bytes in the receiver with the result of a bitAnd operation.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1763
     Warning: this is a destructive operation - elements in the receiver are overwritten."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1764
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1765
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitAnd:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1766
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1767
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1768
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1769
	bitAndBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1770
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1771
	bitAndBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1772
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1773
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1774
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1775
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1776
bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:ruleSymbol
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1777
    "perform a special case of an aligned bitBlit operation.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1778
     Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1779
     of some logical operation, as specified by the ruleSymbol.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1780
     SourceBytes are fetched starting at sourceOffset.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1781
     Valid rule symbols are:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1782
	#copy    - trivial;  same as replaceBytesFrom:to:with:startingAt:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1783
	#bitXor: - xoring;   byte[dI] = byte[dI] bitXor:(srcByte[sI])
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1784
	#bitAnd: - anding;   byte[dI] = byte[dI] bitAnd:(srcByte[sI])
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1785
	#bitOr:  - oring;    byte[dI] = byte[dI] bitOr:(srcByte[sI])
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1786
	#+       - adding;   byte[dI] = (byte[dI] + (srcByte[sI])) mod: 256
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1787
	#-       - subtract; byte[dI] = (byte[dI] - (srcByte[sI])) mod: 256
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1788
     Warning: this is a destructive operation - elements in the receiver are overwritten.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1789
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1790
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1791
    |srcIdx|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1792
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1793
%{
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1794
    if ((__isByteArrayLike(sourceBytes))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1795
     && (__qClass(self) == ByteArray)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1796
     && __isSmallInteger(dstStart)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1797
     && __isSmallInteger(dstEnd)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1798
     && __isSmallInteger(sourceStart)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1799
	unsigned char *srcP = __ByteArrayInstPtr(sourceBytes)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1800
	unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1801
	int srcLen = __byteArraySize(sourceBytes);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1802
	int dstLen = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1803
	int __srcStart = __intVal(sourceStart);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1804
	int __dstStart = __intVal(dstStart);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1805
	int count = __intVal(dstEnd) - __dstStart + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1806
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1807
	if ((__dstStart >= 1)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1808
	 && (__srcStart >= 1)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1809
	 && ((__dstStart + count - 1) <= dstLen)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1810
	 && ((__srcStart + count - 1) <= srcLen)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1811
	    srcP += __srcStart - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1812
	    dstP += __dstStart - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1813
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1814
#define OP_LOOP_BYTES(OP) \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1815
    while (count >= 4) {                                             \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1816
	(dstP[0]) OP (srcP[0]);                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1817
	(dstP[1]) OP (srcP[1]);                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1818
	(dstP[2]) OP (srcP[2]);                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1819
	(dstP[3]) OP (srcP[3]);                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1820
	srcP += 4;                                                   \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1821
	dstP += 4;                                                   \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1822
	count -= 4;                                                  \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1823
    }                                                                \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1824
    while (count > 0) {                                              \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1825
	*dstP OP (*srcP);                                            \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1826
	srcP++;                                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1827
	dstP++;                                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1828
	count--;                                                     \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1829
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1830
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1831
#define OP_LOOP(OP) \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1832
    while (count >= 16) {                                            \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1833
	((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]);    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1834
	((unsigned int *)dstP)[1] OP (((unsigned int *)srcP)[1]);    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1835
	((unsigned int *)dstP)[2] OP (((unsigned int *)srcP)[2]);    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1836
	((unsigned int *)dstP)[3] OP (((unsigned int *)srcP)[3]);    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1837
	srcP += 16;                                                  \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1838
	dstP += 16;                                                  \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1839
	count -= 16;                                                 \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1840
    }                                                                \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1841
    while (count >= 4) {                                             \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1842
	((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]);    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1843
	srcP += 4;                                                   \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1844
	dstP += 4;                                                   \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1845
	count -= 4;                                                  \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1846
    }                                                                \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1847
    while (count > 0) {                                              \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1848
	*dstP OP (*srcP);                                            \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1849
	srcP++;                                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1850
	dstP++;                                                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1851
	count--;                                                     \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1852
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1853
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1854
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1855
	    if (ruleSymbol == @symbol(bitXor:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1856
		OP_LOOP( ^= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1857
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1858
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1859
	    if (ruleSymbol == @symbol(bitXorNot:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1860
		OP_LOOP( ^=~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1861
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1862
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1863
	    if (ruleSymbol == @symbol(bitAnd:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1864
		OP_LOOP( &= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1865
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1866
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1867
	    if (ruleSymbol == @symbol(bitAndNot:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1868
		OP_LOOP( &=~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1869
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1870
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1871
	    if (ruleSymbol == @symbol(bitOr:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1872
		OP_LOOP( |= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1873
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1874
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1875
	    if (ruleSymbol == @symbol(bitOrNot:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1876
		OP_LOOP( |=~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1877
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1878
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1879
	    if (ruleSymbol == @symbol(copy)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1880
		OP_LOOP( = )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1881
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1882
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1883
	    if (ruleSymbol == @symbol(copyNot)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1884
		OP_LOOP( =~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1885
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1886
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1887
	    if (ruleSymbol == @symbol(+)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1888
		OP_LOOP_BYTES( += )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1889
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1890
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1891
	    if (ruleSymbol == @symbol(-)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1892
		OP_LOOP_BYTES( -= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1893
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1894
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1895
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1896
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1897
#undef OP_LOOP_BYTES
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1898
#undef OP_LOOP
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1899
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1900
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1901
    ruleSymbol == #copy ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1902
	self replaceFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1903
	^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1904
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1905
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1906
    srcIdx := sourceStart.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1907
    dstStart to:dstEnd do:[:dstIdx |
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1908
	self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:(sourceBytes at:srcIdx)).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1909
	srcIdx := srcIdx + 1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1910
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1911
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1912
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1913
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1914
	bitBlitBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1915
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1916
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1917
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1918
	bitBlitBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#bitAnd:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1919
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1920
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1921
     #[255 0 0 0 0 0 0 0]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1922
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1923
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1924
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1925
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1926
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1927
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1928
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#copyNot
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1929
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1930
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1931
	bitBlitBytesFrom:1 to:8 with:(1 to:8) startingAt:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1932
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1933
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1934
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1935
bitBlitBytesFrom:dstStart to:dstEnd withConstant:sourceByte rule:ruleSymbol
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1936
    "perform a special case of an aligned bitBlit operation.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1937
     Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1938
     of some logical operation, as specified by the ruleSymbol.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1939
     Valid rule symbols are:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1940
	#copy    - trivial;  same as from:to:put:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1941
	#bitXor: - xoring;   byte[dI] = byte[dI] bitXor:sourceConst
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1942
	#bitAnd: - anding;   byte[dI] = byte[dI] bitAnd:sourceConst
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1943
	#bitOr:  - oring;    byte[dI] = byte[dI] bitOr:sourceConst
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1944
	#+       - adding;   byte[dI] = (byte[dI] + sourceConst) mod: 256
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1945
	#-       - subtract; byte[dI] = (byte[dI] - sourceConst) mod: 256
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1946
     Warning: this is a destructive operation - elements in the receiver are overwritten.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1947
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1948
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1949
    |srcIdx|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1950
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1951
%{
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1952
    if ((__qClass(self) == ByteArray)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1953
     && __isSmallInteger(dstStart)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1954
     && __isSmallInteger(dstEnd)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1955
     && __isSmallInteger(sourceByte)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1956
	unsigned char srcByte = __intVal(sourceByte);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1957
	unsigned srcWord;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1958
	unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1959
	int dstLen = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1960
	int __dstStart = __intVal(dstStart);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1961
	int count = __intVal(dstEnd) - __dstStart + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1962
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1963
	srcWord = (srcByte << 8) | srcByte;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1964
	srcWord = (srcWord << 16) | srcWord;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1965
	if ((__dstStart >= 1)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1966
	 && ((__dstStart + count - 1) <= dstLen)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1967
	    dstP += __dstStart - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1968
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1969
#define OP_LOOP_BYTES(OP) \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1970
    while (count >= 4) {                         \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1971
	dstP[0] OP srcByte;                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1972
	dstP[1] OP srcByte;                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1973
	dstP[2] OP srcByte;                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1974
	dstP[3] OP srcByte;                      \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1975
	dstP += 4;                               \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1976
	count -= 4;                              \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1977
    }                                            \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1978
    while (count > 0) {                          \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1979
	*dstP OP srcByte;                        \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1980
	dstP++;                                  \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1981
	count--;                                 \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1982
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1983
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1984
#define OP_LOOP_INT32(OP) \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1985
    while (count >= 16) {                        \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1986
	((unsigned int *)dstP)[0] OP srcWord;    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1987
	((unsigned int *)dstP)[1] OP srcWord;    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1988
	((unsigned int *)dstP)[2] OP srcWord;    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1989
	((unsigned int *)dstP)[3] OP srcWord;    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1990
	dstP += 16;                              \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1991
	count -= 16;                             \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1992
    }                                            \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1993
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1994
#define OP_LOOP(OP) \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1995
    OP_LOOP_INT32(OP)                            \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1996
    while (count >= 4) {                         \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1997
	((unsigned int *)dstP)[0] OP srcWord;    \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1998
	dstP += 4;                               \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  1999
	count -= 4;                              \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2000
    }                                            \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2001
    while (count > 0) {                          \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2002
	*dstP OP srcByte;                        \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2003
	dstP++;                                  \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2004
	count--;                                 \
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2005
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2006
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2007
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2008
	    if (ruleSymbol == @symbol(bitXor:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2009
		OP_LOOP( ^= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2010
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2011
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2012
	    if (ruleSymbol == @symbol(bitXorNot:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2013
		OP_LOOP( ^=~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2014
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2015
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2016
	    if (ruleSymbol == @symbol(bitAnd:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2017
		OP_LOOP( &= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2018
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2019
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2020
	    if (ruleSymbol == @symbol(bitAndNot:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2021
		OP_LOOP( &=~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2022
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2023
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2024
	    if (ruleSymbol == @symbol(bitOr:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2025
		OP_LOOP( |= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2026
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2027
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2028
	    if (ruleSymbol == @symbol(bitOrNot:)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2029
		OP_LOOP( |=~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2030
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2031
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2032
	    if (ruleSymbol == @symbol(copy)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2033
		OP_LOOP( = )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2034
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2035
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2036
	    if (ruleSymbol == @symbol(copyNot)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2037
		OP_LOOP( =~ )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2038
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2039
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2040
	    if (ruleSymbol == @symbol(+)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2041
		OP_LOOP_BYTES( += )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2042
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2043
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2044
	    if (ruleSymbol == @symbol(-)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2045
		OP_LOOP_BYTES( -= )
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2046
		RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2047
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2048
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2049
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2050
#undef OP_LOOP_BYTES
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2051
#undef OP_LOOP
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2052
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2053
    ruleSymbol == #copy ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2054
	self from:dstStart to:dstEnd put:sourceByte.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2055
	^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2056
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2057
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2058
    dstStart to:dstEnd do:[:dstIdx |
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2059
	self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:sourceByte).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2060
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2061
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2062
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2063
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2064
	bitBlitBytesFrom:1 to:3 withConstant:1 rule:#bitXor:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2065
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2066
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitXor:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2067
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2068
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitAnd:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2069
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2070
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2071
     #[255 0 0 0 0 0 0 0]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2072
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2073
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2074
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2075
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2076
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#-
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2077
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2078
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#copyNot
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2079
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2080
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2081
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2082
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2083
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2084
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2085
bitOrBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2086
    "replace bytes in the receiver with the result of a bitOr operation.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2087
     Warning: this is a destructive operation - elements in the receiver are overwritten."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2088
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2089
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitOr:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2090
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2091
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2092
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2093
	bitOrBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2094
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2095
	bitOrBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2096
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2097
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2098
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2099
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2100
bitXorBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2101
    "replace bytes in the receiver with the result of an bitXor operation.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2102
     Warning: this is a destructive operation - elements in the receiver are overwritten."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2103
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2104
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitXor:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2105
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2106
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2107
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2108
	bitXorBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2109
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2110
	bitXorBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2111
     #[1 2 3 4 5 6 7 8]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2112
	bitXorBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2113
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2114
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2115
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2116
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2117
compressPixels:nBitsPerPixel width:width height:height into:aByteArray mapping:aMapByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2118
    "given the receiver with 8-bit pixels, compress them into aByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2119
     with nBitsPerPixel-depth pixels. The width/height-arguments are needed
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2120
     to allow for any padding. On the fly, the source bytes are translated
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2121
     using aMapByteArray (if non-nil).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2122
     Notice that smalltalk indexing begins at 1; thus the map-index for a byte
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2123
     value of n is found in map at:(n + 1).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2124
     Output bits are filled left-to right, i.e. the first byte in the input
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2125
     corresponds to the high bit(s) if the first byte in the input.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2126
     This method can be used to convert 8-bit image data to mono, 2-bit and 4-bit
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2127
     bitmaps.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2128
     It can also be used to compress byte-arrays into bitArrays."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2129
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2130
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2131
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2132
    REGISTER unsigned char *src, *dst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2133
    REGISTER int wrun;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2134
    unsigned char *dstNext;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2135
    unsigned char *dstEnd;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2136
    int bytesPerRow, mask, shift0, shift;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2137
    int w, h, hrun;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2138
    int srcBytes, dstBytes;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2139
    int bitsPerPixel;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2140
    int bits;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2141
    int ncells;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2142
    unsigned char *map;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2143
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2144
    if ((__qClass(self) == @global(ByteArray))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2145
     && (__qClass(aByteArray) == @global(ByteArray))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2146
     && __isSmallInteger(nBitsPerPixel)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2147
     && __bothSmallInteger(height, width)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2148
	if ((aMapByteArray != nil)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2149
	 && (__Class(aMapByteArray) == @global(ByteArray))) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2150
	    map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2151
	} else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2152
	    map = (unsigned char *)0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2153
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2154
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2155
	bitsPerPixel = __intVal(nBitsPerPixel);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2156
	w = __intVal(width);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2157
	h = __intVal(height);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2158
	src = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2159
	dst = __ByteArrayInstPtr(aByteArray)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2160
	dstEnd = dst + __byteArraySize(aByteArray);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2161
	switch (bitsPerPixel) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2162
	    case 1:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2163
		mask = 0x01;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2164
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2165
	    case 2:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2166
		mask = 0x03;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2167
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2168
	    case 4:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2169
		mask = 0x0F;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2170
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2171
	    case 8:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2172
		mask = 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2173
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2174
	    default:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2175
		console_printf("invalid depth in compressPixels\n");
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2176
		goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2177
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2178
	if (map) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2179
	    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2180
	     * if a map is present, it must have entries for
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2181
	     * all possible byte-values (i.e. its size must be >= 256)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2182
	     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2183
	    if ((__qSize(aMapByteArray) - OHDR_SIZE) < 256) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2184
		console_printf("invalid map in compressPixels\n");
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2185
		goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2186
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2187
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2188
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2189
	bytesPerRow = (w * bitsPerPixel + 7) / 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2190
	dstBytes = bytesPerRow * h;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2191
	srcBytes = w * h;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2192
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2193
	if ((__byteArraySize(self) >= srcBytes)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2194
	 && (__byteArraySize(aByteArray) >= dstBytes)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2195
	    for (hrun=h; hrun; hrun--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2196
		dstNext = dst + bytesPerRow;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2197
		bits = 0; shift = 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2198
		if (map) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2199
		    for (wrun=w; wrun; wrun--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2200
			bits = (bits << bitsPerPixel) | (map[*src++] & mask);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2201
			shift -= bitsPerPixel;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2202
			if (shift == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2203
			    if (dst == dstEnd) goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2204
			    *dst++ = bits;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2205
			    bits = 0; shift = 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2206
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2207
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2208
		} else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2209
		    for (wrun=w; wrun; wrun--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2210
			bits = (bits << bitsPerPixel) | (*src++ & mask);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2211
			shift -= bitsPerPixel;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2212
			if (shift == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2213
			    if (dst == dstEnd) goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2214
			    *dst++ = bits;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2215
			    bits = 0; shift = 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2216
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2217
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2218
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2219
		if (shift != 8) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2220
		    if (dst == dstEnd) goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2221
		    *dst = bits;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2222
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2223
		dst = dstNext;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2224
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2225
	    RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2226
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2227
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2228
fail: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2229
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2230
    self primitiveFailed
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2231
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2232
    "Example1:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2233
     compress 1 byte-per-pixel bitmap to 1-bit-per-pixel bitmap
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2234
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2235
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2236
     |inBits outBits|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2237
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2238
     inBits := #[0 0 0 0 1 1 1 1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2239
		 0 0 1 1 0 0 1 1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2240
		 0 1 0 1 0 1 0 1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2241
		 1 1 1 1 0 0 0 0].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2242
     outBits := ByteArray new:4.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2243
     inBits compressPixels:1 width:8 height:4
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2244
		    into:outBits mapping:nil.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2245
     outBits inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2246
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2247
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2248
    "Example2:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2249
     compress byte-array into a bitArray, translating 99 to 0-bits,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2250
     and 176 to 1-bits. (just a stupid example)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2251
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2252
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2253
     |inBits outBits map|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2254
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2255
     inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2256
     map := ByteArray new:256.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2257
     map at:176+1 put:1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2258
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2259
     outBits := ByteArray new:2.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2260
     inBits compressPixels:1 width:16 height:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2261
		    into:outBits mapping:map.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2262
     outBits inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2263
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2264
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2265
    "Example3:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2266
     compress byte-array into a bitArray, translating everything below 128 to 0-bits,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2267
     and 128 to 255 to 1-bits.99 to 0-bits (another stupid example)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2268
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2269
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2270
     |inBits outBits map|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2271
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2272
     inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2273
     map := ByteArray new:256.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2274
     map atAll:(128+1 to:255+1) put:1.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2275
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2276
     outBits := ByteArray new:2.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2277
     inBits compressPixels:1 width:16 height:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2278
		    into:outBits mapping:map.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2279
     outBits inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2280
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2281
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2282
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2283
expandPixels:nBitsPerPixel width:width height:height into:aByteArray mapping:aMapByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2284
    "given the receiver with nBitsPerPixel-depth pixels, expand them into
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2285
     aByteArray with 8-bit pixels. The width/height-arguments are needed
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2286
     to skip any padded src-bits. On the fly, the destination pixels
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2287
     are translated using aMapByteArray (if non-nil).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2288
     Input bits are read left-to right, i.e. the first byte in the output
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2289
     corresponds to the high bit(s) in the inputs first byte.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2290
     This is used to display mono, 2-bit and 4-bit bitmaps on grey-scale/color
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2291
     machines. With nBitsPerPixel==8, this is a translate operation.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2292
     Notice that smalltalk indexing begins at 1; thus the map-index for a byte
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2293
     value of n is found in map at:(n + 1).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2294
     It can also be used to expand bit-arrays into byteArrays.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2295
     This method is specialized for ByteArray arguments - it will not handle
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2296
     anything else."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2297
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2298
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2299
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2300
    REGISTER unsigned char *src, *dst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2301
    REGISTER int wrun;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2302
    unsigned char *srcNext;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2303
    int bytesPerRow, mask, shift0, shift;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2304
    int w, h, hrun;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2305
    int srcBytes, dstBytes;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2306
    int bitsPerPixel;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2307
    int bits;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2308
    int ncells;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2309
    unsigned char *map;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2310
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2311
    if ((__qClass(self) == @global(ByteArray))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2312
     && (__qClass(aByteArray) == @global(ByteArray))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2313
     && __isSmallInteger(nBitsPerPixel)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2314
     && __bothSmallInteger(height, width)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2315
	if ((aMapByteArray != nil)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2316
	 && (__Class(aMapByteArray) == @global(ByteArray))) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2317
	    map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2318
	} else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2319
	    map = (unsigned char *)0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2320
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2321
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2322
	bitsPerPixel = __intVal(nBitsPerPixel);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2323
	w = __intVal(width);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2324
	h = __intVal(height);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2325
	src = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2326
	dst = __ByteArrayInstPtr(aByteArray)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2327
	switch (bitsPerPixel) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2328
	    case 1:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2329
		mask = 0x01;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2330
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2331
	    case 2:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2332
		mask = 0x03;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2333
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2334
	    case 4:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2335
		mask = 0x0F;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2336
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2337
	    case 8:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2338
		mask = 0xFF;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2339
		break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2340
	    default:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2341
		console_printf("expandPixels: invalid depth\n");
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2342
		goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2343
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2344
	ncells = mask + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2345
	if (map) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2346
	    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2347
	     * if a map is present, it must have the correct size
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2348
	     * (i.e. 2 raisedTo:nBitsPerPixel)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2349
	     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2350
	    if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2351
		console_printf("expandPixels: invalid map\n");
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2352
		goto fail;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2353
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2354
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2355
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2356
	bytesPerRow = (w * bitsPerPixel + 7) / 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2357
	shift0 = 8 - bitsPerPixel;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2358
	srcBytes = bytesPerRow * h;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2359
	dstBytes = w * h;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2360
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2361
	if ((__byteArraySize(self) >= srcBytes)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2362
	 && (__byteArraySize(aByteArray) >= dstBytes)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2363
	    for (hrun=h; hrun; hrun--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2364
		srcNext = src + bytesPerRow;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2365
		shift = shift0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2366
		if (map) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2367
		    if (shift0 == 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2368
			/* translate only */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2369
			for (wrun=w; wrun; wrun--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2370
			    bits = *src++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2371
			    *dst++ = map[bits];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2372
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2373
		    } else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2374
			for (wrun=w; wrun; wrun--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2375
			    if (shift == shift0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2376
				bits = *src++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2377
			    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2378
			    *dst++ = map[(bits >> shift) & mask];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2379
			    shift -= bitsPerPixel;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2380
			    if (shift < 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2381
				shift = shift0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2382
			    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2383
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2384
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2385
		} else {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2386
		    for (wrun=w; wrun; wrun--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2387
			if (shift == shift0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2388
			    bits = *src++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2389
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2390
			*dst++ = (bits >> shift) & mask;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2391
			shift -= bitsPerPixel;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2392
			if (shift < 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2393
			    shift = shift0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2394
			}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2395
		    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2396
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2397
		src = srcNext;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2398
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2399
	    RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2400
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2401
	console_printf("expandPixels: buffer size: self:%"_ld_" expect at least:%"_ld_"\n",
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2402
		(INT)(__byteArraySize(self)), (INT)srcBytes);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2403
	console_printf("expandPixels: buffer size: arg:%"_ld_" expect at least:%"_ld_"\n",
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2404
		(INT)(__byteArraySize(aByteArray)), (INT)dstBytes);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2405
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2406
    console_printf("expandPixels: invalid args\n");
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2407
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2408
fail: ;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2409
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2410
    self primitiveFailed
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2411
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2412
    "Example1:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2413
     expand 1-bit-per-pixel bitmap into a 1byte-per-pixel byteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2414
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2415
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2416
     |inBits outBits|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2417
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2418
     inBits := #[2r11110000
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2419
		 2r11001100
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2420
		 2r01010101
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2421
		 2r00001111].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2422
     outBits := ByteArray new:(8*4).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2423
     inBits expandPixels:1 width:8 height:4
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2424
		    into:outBits mapping:nil.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2425
     outBits inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2426
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2427
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2428
    "Example2:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2429
     expand bit-array into a byteArray, translating 0-bits to 99,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2430
     1-bits to 176. (just a stupid example)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2431
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2432
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2433
     |inBits outBits|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2434
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2435
     inBits := #[2r11110000 2r11001100].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2436
     outBits := ByteArray new:16.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2437
     inBits expandPixels:1 width:16 height:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2438
		    into:outBits mapping:#[99 176].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2439
     outBits inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2440
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2441
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2442
    "This Can also be used to extract nibbles ..."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2443
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2444
     |inBits outBits|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2445
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2446
     inBits := #[ 16r12 16r34 16r56 16r78 16r9A 16rBC 16rDE 16rF0 ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2447
     outBits := ByteArray new:(inBits size * 2).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2448
     inBits expandPixels:4 width:outBits size height:1 into:outBits mapping:nil.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2449
     outBits inspect
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2450
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2451
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2452
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2453
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2454
invert
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2455
    "invert all bytes inplace - used with image manipulations
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2456
     written as a primitive for speed.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2457
     Warning: destructive; modifies the receiver - not a copy.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2458
     Q: is this really needed ?"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2459
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2460
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2461
    REGISTER unsigned char *dst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2462
    REGISTER unsigned long *ldst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2463
    REGISTER int cnt;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2464
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2465
    if (__qClass(self) == @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2466
        cnt = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2467
        dst = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2468
        if (((INT)dst & (sizeof(long)-1)) == 0) { // aligned
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2469
            ldst = (unsigned long *)dst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2470
            while (cnt >= (sizeof(long))*4) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2471
                ldst[0] = ~(ldst[0]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2472
                ldst[1] = ~(ldst[1]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2473
                ldst[2] = ~(ldst[2]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2474
                ldst[3] = ~(ldst[3]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2475
                ldst += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2476
                cnt -= (sizeof(long))*4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2477
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2478
            while (cnt >= sizeof(long)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2479
                *ldst = ~(*ldst);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2480
                ldst++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2481
                cnt -= sizeof(long);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2482
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2483
            dst = (unsigned char *)ldst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2484
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2485
        while (cnt--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2486
            *dst = ~(*dst);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2487
            dst++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2488
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2489
        RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2490
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2491
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2492
    self bitBlitBytesFrom:1 to:self size withConstant:16rFF rule:#bitXor:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2493
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2494
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2495
     #[1 2 3 4 5 6 7 8 9 10] copy invert
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2496
     #[1 2 3 4 5 6 7 8 9 10] copy
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2497
        bitBlitBytesFrom:1 to:10 withConstant:16rFF rule:#bitXor:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2498
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2499
     |l|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2500
     l := ByteArray fromHexString:'0102030405060708090a0b0c0d0e0f1112131415161718191a1b1c1d1e1f'.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2501
     Time millisecondsToRun:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2502
        1000000 timesRepeat:[ l invert ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2503
     ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2504
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2505
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2506
    "Modified (comment): / 03-06-2019 / 18:08:47 / Claus Gittinger"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2507
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2508
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2509
reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2510
    "reverse the order of my elements inplace -
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2511
     WARNING: this is a destructive operation, which modifies the receiver.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2512
              Please use reversed (with a 'd' at the end) for a functional version.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2513
     Written as a primitive for speed on image manipulations (mirror)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2514
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2515
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2516
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2517
    REGISTER unsigned char *p1, *p2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2518
    REGISTER int cnt;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2519
    REGISTER unsigned t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2520
    OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2521
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2522
    if (__qClass(self) == @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2523
        cnt = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2524
        p1 = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2525
        p2 = p1 + cnt - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2526
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2527
#if defined(__BSWAP)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2528
        /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2529
         * can we use the bswap instruction ?
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2530
         * notice - not all CPUs have it (the HAS_BSWAP checks this).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2531
         */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2532
        if (__HAS_BSWAP()
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2533
         && ((cnt & 3) == 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2534
            unsigned int *ip1, *ip2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2535
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2536
            ip1 = (unsigned int *)p1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2537
            ip2 = (unsigned int *)(p2 - 3);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2538
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2539
            ip2 -= 7;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2540
            while (ip1 <= ip2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2541
                int t1, t2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2542
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2543
                t1 = ip1[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2544
                t2 = ip2[7];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2545
                ip2[7] = __BSWAP(t1);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2546
                ip1[0] = __BSWAP(t2);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2547
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2548
                t1 = ip1[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2549
                t2 = ip2[6];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2550
                ip2[6] = __BSWAP(t1);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2551
                ip1[1] = __BSWAP(t2);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2552
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2553
                t1 = ip1[2];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2554
                t2 = ip2[5];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2555
                ip2[5] = __BSWAP(t1);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2556
                ip1[2] = __BSWAP(t2);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2557
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2558
                t1 = ip1[3];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2559
                t2 = ip2[4];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2560
                ip2[4] = __BSWAP(t1);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2561
                ip1[3] = __BSWAP(t2);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2562
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2563
                ip1 += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2564
                ip2 -= 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2565
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2566
            ip2 += 7;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2567
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2568
            while (ip1 < ip2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2569
                int t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2570
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2571
                t = __BSWAP(*ip1);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2572
                *ip1++ = __BSWAP(*ip2);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2573
                *ip2-- = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2574
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2575
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2576
            if (ip1 == ip2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2577
                int t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2578
                t = *ip1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2579
                t = __BSWAP(t);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2580
                *ip1 = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2581
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2582
            RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2583
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2584
#endif /* __BSWAP (i.e. __i386__ && __GNUC__) */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2585
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2586
        p2 -= 7;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2587
        while (p1 <= p2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2588
            t = p1[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2589
            p1[0] = p2[7];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2590
            p2[7] = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2591
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2592
            t = p1[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2593
            p1[1] = p2[6];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2594
            p2[6] = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2595
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2596
            t = p1[2];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2597
            p1[2] = p2[5];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2598
            p2[5] = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2599
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2600
            t = p1[3];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2601
            p1[3] = p2[4];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2602
            p2[4] = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2603
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2604
            p1 += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2605
            p2 -= 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2606
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2607
        p2 += 7;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2608
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2609
        while (p1 < p2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2610
            t = *p1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2611
            *p1++ = *p2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2612
            *p2-- = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2613
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2614
        RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2615
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2616
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2617
    ^ super reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2618
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2619
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2620
     #[1 2 3 4 5] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2621
     #[] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2622
     #[1] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2623
     #[1 2] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2624
     #[1 2 3] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2625
     #[1 2 3 4] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2626
     #[1 2 3 4 5] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2627
     #[1 2 3 4 5 6] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2628
     #[1 2 3 4 5 6 7] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2629
     #[1 2 3 4 5 6 7 8] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2630
     #[1 2 3 4 5 6 7 8] copy reverseFrom:2 to:5
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2631
     #[1 2 3 4 5 6 7 8 9] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2632
     #[1 2 3 4 5 6 7 8 9 10] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2633
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2634
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2635
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] copy reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2636
     (1 to:255) asByteArray reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2637
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2638
     1 to:1024 do:[:i|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2639
        |bytes test rBytes|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2640
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2641
        bytes := ((1 to:i) asArray collect:[:i | i bitAnd:255]) asByteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2642
        test := ((i to:1 by:-1) asArray collect:[:i | i bitAnd:255]) asByteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2643
        rBytes := bytes copy.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2644
        rBytes reverse ~= test ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2645
            self halt
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2646
        ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2647
        rBytes := bytes copy.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2648
        rBytes reverse reverse ~= bytes ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2649
            self halt
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2650
        ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2651
     ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2652
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2653
     Time millisecondsToRun:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2654
        10000000 timesRepeat:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2655
            #[1 2 3 4 5 6 7 8] reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2656
        ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2657
     ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2658
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2659
     |b|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2660
     b := (0 to:255) asByteArray.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2661
     Time millisecondsToRun:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2662
        10000000 timesRepeat:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2663
            b reverse
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2664
        ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2665
     ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2666
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2667
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2668
    "Modified (comment): / 01-05-2017 / 12:56:13 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2669
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2670
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2671
swap:i1 with:i2
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2672
   "spap the bytes at i1 and i2"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2673
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2674
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2675
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2676
    REGISTER unsigned char *p;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2677
    unsigned int __i1, __i2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2678
    int sz;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2679
    unsigned int t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2680
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2681
    if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2682
        __i1 = __intVal(i1) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2683
        __i2 = __intVal(i2) - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2684
        sz = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2685
        p = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2686
        if ((__i1 < sz) && (__i2 < sz)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2687
            t = p[__i1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2688
            p[__i1] = p[__i2];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2689
            p[__i2] = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2690
            RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2691
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2692
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2693
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2694
    ^ super swap:i1 with:i2 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2695
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2696
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2697
     #[1 2 3 4 5 6 7 8 9 10] copy swapIndex:1 and:10
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2698
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapIndex:5 and:6
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2699
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2700
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2701
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2702
swapBytes
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2703
    "swap bytes (of int16s) inplace -
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2704
     Expects that the receiver has an even number of bytes;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2705
     if not, only the pairs excluding the last byte are swapped.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2706
     written as a primitive for speed on image grabbing (if display order is different)."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2707
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2708
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2709
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2710
    REGISTER unsigned char *p;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2711
    REGISTER int cnt;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2712
    REGISTER unsigned t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2713
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2714
    if (__qClass(self) == @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2715
        cnt = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2716
        cnt = cnt & ~1; /* make it even */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2717
        p = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2718
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2719
        while (cnt >= sizeof(INT)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2720
            unsigned INT i = ((unsigned INT *)p)[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2721
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2722
#if __POINTER_SIZE__ == 8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2723
            i = ((i>>8) & 0x00FF00FF00FF00FF) | ((i & 0x00FF00FF00FF00FF) << 8);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2724
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2725
            i = ((i>>8) & 0x00FF00FF) | ((i & 0x00FF00FF) << 8);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2726
#endif /* __POINTER_SIZE__ */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2727
            ((unsigned INT *)p)[0] = i;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2728
            p += sizeof(INT);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2729
            cnt -= sizeof(INT);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2730
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2731
        while (cnt > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2732
            unsigned short s;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2733
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2734
            s = ((unsigned short *)p)[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2735
            s = (s >> 8) | (s << 8);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2736
            ((unsigned short *)p)[0] = s;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2737
            p += 2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2738
            cnt -= 2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2739
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2740
        RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2741
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2742
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2743
    ^ super swapBytes "/ rubbish - there is no one currenly
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2744
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2745
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2746
     #[1 2 3 4 5 6 7 8 9 10] copy swapBytes     -> #[2 1 4 3 6 5 8 7 10 9]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2747
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes  -> #[2 1 4 3 6 5 8 7 10 9 11]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2748
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] copy swapBytes
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2749
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2750
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2751
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2752
swapLongs
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2753
    "swap long bytes inplace
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2754
     - any partial longs at the end are not swapped."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2755
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2756
    self swapLongsFrom:1 to:self size
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2757
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2758
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2759
     #[1 2 3 4 5 6 7 8 9] copy swapLongs
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2760
     #[1 2 3 4 5 6 7 8 9 10] copy swapLongs
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2761
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapLongs
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2762
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy swapLongs
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2763
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2764
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2765
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2766
swapLongsFrom:startIndex to:endIndex
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2767
    "swap longs (int32s) inplace
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2768
     - any partial longs at the end are not swapped.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2769
     Swapping is from startIndex to (exclusiv) endIndex;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2770
     indexing starts at 1."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2771
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2772
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2773
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2774
    REGISTER unsigned char *p;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2775
    REGISTER int limit;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2776
    REGISTER unsigned t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2777
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2778
    if ((__qClass(self) == @global(ByteArray))
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2779
     && __isSmallInteger(startIndex)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2780
     && __isSmallInteger(endIndex)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2781
        int __idx = __intVal(startIndex);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2782
        int __endIdx = __intVal(endIndex);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2783
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2784
        limit = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2785
        if (__endIdx < limit) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2786
            limit = __endIdx;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2787
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2788
        p = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2789
        p = p + __idx - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2790
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2791
        limit = limit - 4 + 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2792
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2793
#if defined(__BSWAP)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2794
        /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2795
         * can we use the bswap instruction ?
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2796
         * notice - not all CPUs have it (the HAS_BSWAP checks this).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2797
         */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2798
        if (__HAS_BSWAP()
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2799
         && (((unsigned int)p & 3) == 0)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2800
            unsigned int *ip;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2801
            ip = (unsigned int *)p;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2802
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2803
            while (__idx <= limit) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2804
                *ip = __BSWAP(*ip);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2805
                ip++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2806
                __idx += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2807
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2808
            RETURN (self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2809
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2810
#endif /* __BSWAP */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2811
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2812
        while (__idx <= limit) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2813
            t = p[0];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2814
            p[0] = p[3];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2815
            p[3] = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2816
            t = p[1];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2817
            p[1] = p[2];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2818
            p[2] = t;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2819
            p += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2820
            __idx += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2821
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2822
        RETURN ( self );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2823
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2824
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2825
    ^ super swapLongsFrom:startIndex to:endIndex "/ rubbish - there is no one currenly
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2826
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2827
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2828
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:3
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2829
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:4
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2830
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:5
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2831
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:6
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2832
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:7
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2833
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2834
     #[1 2 3 4 5 6 7 8 9 10] copy swapLongsFrom:1 to:11
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2835
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapLongsFrom:1 to:12
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2836
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy swapLongsFrom:1 to:13
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2837
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:5 to:10
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2838
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2839
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2840
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2841
!ByteArray methodsFor:'inspecting'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2842
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2843
inspectorExtraAttributes
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2844
    "extra (pseudo instvar) entries to be shown in an inspector."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2845
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2846
    |basePrinter|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2847
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2848
    basePrinter := 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2849
        [:arr :b |
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2850
            String
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2851
                streamContents:[:s |
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2852
                    arr class isWords ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2853
                        arr asWordArray printOn:s base:b showRadix:true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2854
                    ] ifFalse:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2855
                        arr class isLongs ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2856
                            arr asLongIntegerArray printOn:s base:b showRadix:true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2857
                        ] ifFalse:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2858
                            arr asByteArray printOn:s base:b showRadix:true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2859
                        ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2860
                    ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2861
                ]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2862
        ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2863
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2864
    ^ super inspectorExtraAttributes
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2865
        add:'-hexstring'   -> [ self hexPrintString "WithSeparator:Character space" ];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2866
        add:'-hexadecimal' -> [ basePrinter value:self value:16 ];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2867
        add:'-binary'      -> [ basePrinter value:self value:2 ];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2868
        add:'-base64'      -> [ self base64Encoded ];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2869
        add:'-asciiString' -> [ self asString ];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2870
        add:'-cString'     -> [ '{',(String streamContents:[:s | self do:[:b | s printf:'0x%02x' with:b ] separatedBy:[s nextPutAll:', ']]), '}' ];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2871
        yourself
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2872
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2873
    "Modified (format): / 18-07-2017 / 19:56:54 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2874
    "Modified: / 19-09-2018 / 12:08:42 / Claus Gittinger"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2875
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2876
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2877
inspectorValueStringInListFor:anInspector
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2878
    "returns a string to be shown in the inspector's list"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2879
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2880
    |sz|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2881
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2882
    (sz := self size) <= 5 ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2883
        ^ self printString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2884
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2885
    ^ (super inspectorValueStringInListFor:anInspector)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2886
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2887
    "Created: / 05-09-2017 / 10:55:27 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2888
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2889
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2890
!ByteArray methodsFor:'printing & storing'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2891
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2892
displayOn:aGCOrStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2893
    "return a printed representation of the receiver for displaying"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2894
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2895
    |cls|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2896
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2897
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2898
    "/ old ST80 means: draw-yourself on a GC.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2899
    cls := self class.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2900
    ((cls == ByteArray or:[cls == ImmutableByteArray]) and:[aGCOrStream isStream]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2901
        self storeOn:aGCOrStream.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2902
        ^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2903
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2904
    ^ super displayOn:aGCOrStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2905
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2906
    "Created: / 25-10-1995 / 13:33:26 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2907
    "Modified: / 22-04-1996 / 12:54:06 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2908
    "Modified (comment): / 22-02-2017 / 16:54:27 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2909
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2910
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2911
printOn:aStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2912
    "append a printed representation to aStream"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2913
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2914
    |cls|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2915
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2916
    "/ care for subclasses
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2917
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2918
	aStream nextPutAll:'#['.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2919
	self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2920
	    do:[:byte | byte printOn:aStream]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2921
	    separatedBy:[aStream space].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2922
	aStream nextPut:$].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2923
	^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2924
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2925
    ^ super printOn:aStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2926
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2927
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2928
     #[1 2 3 4 5] printOn:Transcript
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2929
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2930
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2931
     #[1 2 3 4 5] storeString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2932
     #[1 2 3 4 5] displayString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2933
     #[1 2 3 4 5] printString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2934
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2935
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2936
    "Modified: / 12.9.1997 / 22:11:33 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2937
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2938
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2939
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2940
printOn:aStream base:radix
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2941
    "append a printed representation to aStream in the given number base."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2942
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2943
    ^ self printOn:aStream base:radix showRadix:false
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2944
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2945
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2946
     #[1 2 3 4 5] printOn:Transcript base:2
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2947
     'Hello World' printOn:Transcript base:2
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2948
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2949
     #[1 2 3 4 5] storeString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2950
     #[1 2 3 4 5] displayString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2951
     #[1 2 3 4 5] printString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2952
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2953
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2954
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2955
    "Modified: / 31.10.2001 / 09:43:56 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2956
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2957
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2958
printOn:aStream base:radix showRadix:showRadix
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2959
    "append a printed representation to aStream in the given number base."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2960
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2961
    |cls|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2962
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2963
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2964
	"/ care for subclasses
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2965
	aStream nextPutAll:'#['.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2966
	self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2967
	    do:[:byte | byte printOn:aStream base:radix showRadix:showRadix]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2968
	    separatedBy:[aStream space].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2969
	aStream nextPut:$].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2970
	^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2971
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2972
    ^ self printOn:aStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2973
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2974
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2975
     #[1 2 3 4 5] printOn:Transcript base:2
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2976
     'Hello World' printOn:Transcript base:2
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2977
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2978
     #[1 2 3 4 5] storeString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2979
     #[1 2 3 4 5] displayString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2980
     #[1 2 3 4 5] printString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2981
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2982
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2983
    "Modified: / 12.9.1997 / 22:11:33 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2984
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2985
    "Created: / 31.10.2001 / 09:43:41 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2986
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2987
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2988
storeOn:aStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2989
    "append a printed representation from which the receiver can be
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2990
     reconstructed to aStream. (reimplemented to make it look better)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2991
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2992
    |cls|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2993
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2994
    cls := self class.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2995
    (cls == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2996
        "/ care for subclasses
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2997
        aStream nextPutAll:'#['.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2998
        self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  2999
            do:[:byte | byte storeOn:aStream]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3000
            separatedBy:[aStream space].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3001
        aStream nextPut:$].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3002
        ^ self
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3003
    ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3004
    ^ super storeOn:aStream
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3005
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3006
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3007
     #[1 2 3 4 5] storeOn:Transcript
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3008
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3009
     #[1 2 3 4 5] storeString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3010
     #[1 2 3 4 5] displayString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3011
     #[1 2 3 4 5] printString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3012
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3013
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3014
    "Modified: / 12-09-1997 / 22:11:33 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3015
    "Modified: / 17-02-2017 / 10:50:37 / stefan"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3016
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3017
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3018
!ByteArray methodsFor:'queries'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3019
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3020
characterSize   
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3021
    "answer the size in bits of my largest character (actually only 7, 8, 16 or 32).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3022
     Needed in case someone writes bytes to a CharacterWriteStream (comanche response)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3023
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3024
    ^ 8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3025
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3026
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3027
containsNon7BitAscii
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3028
    "return true, if any byte in the receiver has the 7th bit on.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3029
     This my look as a too specific operation to be put here,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3030
     put it is very helpful for UTF8 string reading (Java class reader),
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3031
     to quickly determine, if UTF8 decoding is needed or not.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3032
     As most strings in a class file are in fact only containing 7bit ascii,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3033
     this should speedup class file reading considerably"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3034
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3035
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3036
    REGISTER unsigned char *cp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3037
    REGISTER unsigned char *endP;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3038
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3039
    if (__isByteArrayLike(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3040
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3041
	endP = cp + __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3042
#if __POINTER_SIZE__ == 8
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3043
	while (cp+8 < endP) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3044
	    if ( ((unsigned INT *)cp)[0] & 0x8080808080808080) RETURN( true );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3045
	    cp += 8;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3046
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3047
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3048
	while (cp+4 < endP) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3049
	    if ( ((unsigned int *)cp)[0] & 0x80808080) RETURN( true );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3050
	    cp += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3051
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3052
	while (cp < endP) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3053
	    if (*cp++ & 0x80) RETURN( true );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3054
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3055
	RETURN ( false );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3056
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3057
%}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3058
.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3059
    ^ self contains:[:b | b bitTest:16r80].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3060
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3061
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3062
     #[1 2 3 1 2 3 1 2 127 ] containsNon7BitAscii
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3063
     #[1 2 3 1 2 3 1 2 250 251 250 251 255] containsNon7BitAscii
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3064
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3065
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3066
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3067
containsNon8BitElements
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3068
    "return true, if one of my elements is larger than a single byte.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3069
     Per definition not."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3070
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3071
    ^ false.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3072
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3073
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3074
isEmpty
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3075
    "return true if the receiver is empty (i.e. if size == 0)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3076
     Redefined here for performance"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3077
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3078
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3079
#ifndef __SCHTEAM__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3080
    if (__isByteArrayLike(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3081
        RETURN ( (__byteArraySize(self) == 0) ? true : false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3082
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3083
#endif /* ! __SCHTEAM__ */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3084
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3085
    ^ self size == 0
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3086
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3087
    "Created: / 16-02-2017 / 15:02:03 / stefan"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3088
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3089
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3090
isValidElement:anObject
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3091
    "return true, if I can hold this kind of object"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3092
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3093
    "/ notice the self class minVal/maxVal here:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3094
    "/ I am redefined to logically hold longer objects (shortInts, ints, longInts, etc.)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3095
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3096
    ^ anObject isInteger
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3097
    and:[ (anObject >= self class minVal)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3098
    and:[ (anObject <= self class maxVal) ]]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3099
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3100
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3101
max
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3102
    "return the maximum value in the receiver -
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3103
     redefined to speedup image processing and sound-player
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3104
     (which need a fast method for this on byteArrays)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3105
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3106
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3107
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3108
    REGISTER unsigned char *cp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3109
    REGISTER int index, max;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3110
    int len;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3111
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3112
    if (__isByteArrayLike(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3113
        max = 0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3114
        index = 0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3115
        len = __qSize(self) - OHDR_SIZE;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3116
        cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3117
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3118
        if (len > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3119
            while (++index <= len) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3120
                unsigned int byte;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3121
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3122
                byte = *cp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3123
                cp++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3124
                if (byte > max) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3125
                    max = byte;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3126
                    if (byte == 255) break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3127
                }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3128
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3129
            RETURN ( __mkSmallInteger(max) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3130
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3131
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3132
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3133
    ^ super max
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3134
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3135
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3136
     #[1 2 3 1 2 3 1 2 19] max
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3137
     #[] max
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3138
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3139
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3140
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3141
notEmpty
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3142
    "return true if the receiver is not empty (i.e. if size ~~ 0)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3143
     Redefined here for performance"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3144
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3145
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3146
#ifndef __SCHTEAM__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3147
    if (__isByteArrayLike(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3148
        RETURN ( (__byteArraySize(self) != 0) ? true : false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3149
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3150
#endif /* ! __SCHTEAM__ */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3151
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3152
    ^ self size ~~ 0
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3153
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3154
    "Created: / 16-02-2017 / 15:02:36 / stefan"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3155
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3156
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3157
startsWith:aByteOrByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3158
    "return true, if the receiver starts with something, aStringOrChar.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3159
     If the argument is empty, true is returned.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3160
     Notice, that this is similar to, but slightly different from VW's and Squeak's beginsWith:,
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3161
     which are both inconsistent w.r.t. an empty argument."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3162
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3163
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3164
    int len1, len2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3165
    REGISTER unsigned char *src1, *src2;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3166
    unsigned char c;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3167
    REGISTER OBJ slf = self;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3168
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3169
    if (__qIsByteArrayLike(slf) &&__isByteArrayLike(aByteOrByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3170
        src1 = __byteArrayVal(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3171
        src2 = __byteArrayVal(aByteOrByteArray);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3172
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3173
        if (src1[0] != src2[0]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3174
            if (__qSize(aByteOrByteArray) == OHDR_SIZE) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3175
                RETURN (true);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3176
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3177
            RETURN ( false );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3178
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3179
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3180
        len1 = __qSize(slf);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3181
        len2 = __qSize(aByteOrByteArray);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3182
        if (len1 < len2) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3183
            RETURN ( false );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3184
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3185
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3186
# ifdef UINT64
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3187
        while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3188
            if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3189
                RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3190
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3191
            len2 -= sizeof(UINT64);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3192
            src1 += sizeof(UINT64);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3193
            src2 += sizeof(UINT64);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3194
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3195
# else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3196
#  ifdef __UNROLL_LOOPS__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3197
        while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3198
            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3199
                RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3200
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3201
            if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3202
                RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3203
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3204
            if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3205
                RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3206
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3207
            if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3208
                RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3209
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3210
            len2 -= sizeof(INT)*4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3211
            src1 += sizeof(INT)*4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3212
            src2 += sizeof(INT)*4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3213
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3214
#  endif /* __UNROLL_LOOPS__ */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3215
# endif /* UINT64 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3216
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3217
        while (len2 > (OHDR_SIZE+sizeof(INT))) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3218
            if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3219
                RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3220
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3221
            len2 -= sizeof(INT);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3222
            src1 += sizeof(INT);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3223
            src2 += sizeof(INT);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3224
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3225
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3226
        for ( ; len2 > OHDR_SIZE; len2--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3227
            if (*src1++ != *src2++) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3228
                RETURN (false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3229
            }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3230
        }    
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3231
        RETURN (true);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3232
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3233
    if (__isSmallInteger(aByteOrByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3234
        int val = __intVal(aByteOrByteArray);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3235
        if (__byteArraySize(slf) > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3236
            RETURN ( (__byteArrayVal(slf)[0] == val) ? true : false);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3237
        }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3238
        RETURN ( false );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3239
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3240
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3241
    ^ super startsWith:aByteOrByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3242
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3243
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3244
     #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 1 2 3 4 5]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3245
     #[1 2 3 4] startsWith:#[ 1 3 4 5]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3246
     #[1 2 3 4 5 6 7 8 9 10] startsWith:#[ 0 1 2 3 4 5]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3247
     #[1 2 3 4 5 6 7 8 9 10] startsWith:#(1 2 3 4 5)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3248
     #[1 2 3 4 5 6 7 8 9 10] startsWith:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3249
     #[1 2 3 4 5 6 7 8 9 10] startsWith:2
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3250
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3251
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3252
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3253
usageCounts
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3254
    "return an array filled with value-counts -
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3255
     This is needed in the bitmap/image classes to get info on color usage.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3256
     (i.e. to build up a histogram of color usage within an image)."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3257
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3258
    |counts|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3259
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3260
    counts := Array basicNew:256.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3261
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3262
%{  /* STACK: 2000 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3263
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3264
    REGISTER unsigned char *cp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3265
    REGISTER int nByte;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3266
    REGISTER int index;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3267
    INT icounts[256];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3268
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3269
    if (__isByteArrayLike(self) && __isArray(counts)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3270
	/*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3271
	 * zero counts
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3272
	 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3273
	for (index=0; index<256; index++) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3274
	    icounts[index] = 0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3275
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3276
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3277
	/*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3278
	 * count
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3279
	 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3280
	nByte = __qSize(self) - OHDR_SIZE;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3281
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3282
	while (nByte--) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3283
	    icounts[*cp++]++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3284
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3285
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3286
	/*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3287
	 * make it real counts
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3288
	 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3289
	for (index=0; index<256; index++) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3290
	    __ArrayInstPtr(counts)->a_element[index] = __mkSmallInteger(icounts[index]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3291
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3292
	RETURN ( counts );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3293
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3294
%}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3295
.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3296
    self primitiveFailed
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3297
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3298
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3299
     #[1 2 3 1 2 3 1 2 250 251 250 251 255] usageCounts
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3300
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3301
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3302
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3303
usedValues
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3304
    "return a new ByteArray with all used values (actually a kind of Set);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3305
     This is needed specially in the bitmap/Imageclasses to find used colors
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3306
     of an image."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3307
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3308
%{  /* STACK: 400 */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3309
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3310
    REGISTER unsigned char *cp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3311
    unsigned char *endp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3312
    REGISTER int len;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3313
    OBJ result;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3314
    union {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3315
	unsigned char flags[256];
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3316
	int toForceAlignmentOfFlags;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3317
    } f;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3318
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3319
#ifdef TO_BE_MEASURED
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3320
    int coverage = 0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3321
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3322
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3323
    if (__isByteArrayLike(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3324
	memset(f.flags, 0, sizeof(f.flags));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3325
	len = __qSize(self) - OHDR_SIZE;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3326
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3327
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3328
	/* for each used byte, set flag */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3329
	while (len > 0) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3330
#ifdef TO_BE_MEASURED
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3331
	    unsigned  byte;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3332
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3333
	    byte = *cp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3334
	    if (! f.flags[byte]) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3335
		f.flags[byte] = 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3336
		coverage++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3337
		if (coverage == 256) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3338
		    /* no need to scan rest */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3339
		    break;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3340
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3341
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3342
#else
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3343
	    f.flags[*cp] = 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3344
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3345
	    cp++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3346
	    len--;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3347
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3348
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3349
	/* count 1's */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3350
	len = 0;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3351
	for (cp=f.flags, endp=f.flags+256; cp < endp;) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3352
	    if ( *((unsigned int *)cp)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3353
		if (cp[0]) len++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3354
		if (cp[1]) len++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3355
		if (cp[2]) len++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3356
		if (cp[3]) len++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3357
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3358
	    cp += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3359
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3360
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3361
	/* create ByteArray of used values */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3362
	result = __BYTEARRAY_UNINITIALIZED_NEW_INT(len);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3363
	if (result) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3364
	    cp = __ByteArrayInstPtr(result)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3365
	    for (len=0; len < 256; len++) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3366
		if (f.flags[len])
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3367
		    *cp++ = len;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3368
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3369
	    RETURN ( result );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3370
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3371
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3372
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3373
    ^ self asIdentitySet asByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3374
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3375
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3376
     #[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3377
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3378
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3379
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3380
!ByteArray methodsFor:'queries - asn1'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3381
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3382
asn1Type
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3383
    ^ OSI::ASN1_OCTETSTRING primitiveType
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3384
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3385
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3386
!ByteArray methodsFor:'searching'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3387
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3388
indexOf:aByte startingAt:start
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3389
    "return the index of the first occurrence of the argument, aByte
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3390
     in the receiver starting at start, anInteger; return 0 if not found.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3391
     - reimplemented here for speed"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3392
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3393
%{  /* NOCONTEXT */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3394
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3395
    REGISTER unsigned char *cp;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3396
    REGISTER INT index;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3397
    REGISTER int byteValue;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3398
    REGISTER int len;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3399
    OBJ cls;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3400
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3401
    if (__isSmallInteger(aByte) &&__isBytes(self)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3402
	byteValue = __intVal(aByte);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3403
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3404
	if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3405
	    /*
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3406
	     * searching for something which cannot be found
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3407
	     */
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3408
	    RETURN ( __mkSmallInteger(0) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3409
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3410
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3411
	if (__isSmallInteger(start)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3412
	    index = __intVal(start);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3413
	    len = __byteArraySize(self);
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3414
	    cp = __ByteArrayInstPtr(self)->ba_element;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3415
	    if ((cls = __qClass(self)) != @global(ByteArray)) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3416
		int nInst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3417
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3418
		nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3419
		cp += nInst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3420
		len -= nInst;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3421
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3422
	    cp += index - 1;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3423
#ifdef __UNROLL_LOOPS__
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3424
	    while ((index+4) < len) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3425
		if (cp[0] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3426
		if (cp[1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3427
		if (cp[2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3428
		if (cp[3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3429
		index += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3430
		cp += 4;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3431
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3432
#endif
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3433
	    while (index <= len) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3434
		if (*cp == byteValue) {
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3435
		    RETURN ( __mkSmallInteger(index) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3436
		}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3437
		index++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3438
		cp++;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3439
	    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3440
	    RETURN ( __mkSmallInteger(0) );
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3441
	}
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3442
    }
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3443
%}.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3444
    ^ super indexOf:aByte startingAt:start
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3445
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3446
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3447
     #[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0 startingAt:1
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3448
    "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3449
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3450
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3451
!ByteArray methodsFor:'spray'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3452
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3453
printSchemaHexString
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3454
        | stream |
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3455
        #swAdded.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3456
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3457
        stream := WriteStream on:(String new:self size * 2).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3458
        self do:[:eachByte |
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3459
            |s|
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3460
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3461
            stream nextPut:('0123456789ABCDEF' at:((eachByte bitShift:-4) bitAnd:16rF)+1).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3462
            stream nextPut:('0123456789ABCDEF' at:(eachByte bitAnd:16rF)+1).
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3463
        ].
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3464
        ^stream contents
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3465
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3466
        "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3467
         #[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 254 255] printSchemaHexString 
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3468
        "
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3469
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3470
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3471
!ByteArray methodsFor:'testing'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3472
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3473
isByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3474
    "return true, if the receiver is some kind of bytearray;
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3475
     true is returned here - the method is redefined from Object."
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3476
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3477
    ^ true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3478
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3479
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3480
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3481
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3482
isIntegerArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3483
    "return true if the receiver has integer elements.
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3484
     These are Byte- and Integer arrays; both signed and unsigned"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3485
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3486
    ^ true
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3487
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3488
    "Created: / 02-03-2019 / 23:11:00 / Claus Gittinger"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3489
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3490
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3491
isLiteral
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3492
    "return true, if the receiver can be used as a literal constant in ST syntax
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3493
     (i.e. can be used in constant arrays)"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3494
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3495
    "/ no, simply returning true here is a mistake:
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3496
    "/ it could be a subclass of ByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3497
    "/ (of which the compiler does not know at all ...)
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3498
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3499
    ^ self class == ByteArray
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3500
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3501
    "Modified: 22.4.1996 / 12:55:30 / cg"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3502
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3503
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3504
!ByteArray methodsFor:'vm support'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3505
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3506
_ARRAYLENGTH: cls
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3507
    ^self basicSize
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3508
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3509
    "Created: / 14-05-2013 / 10:10:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3510
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3511
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3512
_CHECKCAST: cls
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3513
    ^cls == ByteArray ifTrue:[self] ifFalse:[JavaVM throwClassCastException]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3514
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3515
    "Created: / 14-05-2013 / 10:09:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3516
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3517
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3518
_INSTANCEOF: cls
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3519
    ^ByteArray == cls ifTrue:[1] ifFalse:[0]
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3520
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3521
    "Created: / 14-05-2013 / 10:09:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3522
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3523
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3524
!ByteArray class methodsFor:'documentation'!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3525
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3526
version
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3527
    ^ '$Header$'
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3528
!
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3529
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3530
version_CVS
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3531
    ^ '$Header$'
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3532
! !
b83026fdb8cb #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24743
diff changeset
  3533