FourByteString.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Jun 2019 14:28:51 +0200
changeset 5050 44fa8672d102
parent 4923 6e6fea06fff6
child 5090 33d4825d883d
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedQueue comment/format in: #next #nextWithTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2004 by eXept Software AG
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
1415
3ef6a2c42611 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 1404
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3533
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    14
"{ NameSpace: Smalltalk }"
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    15
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
CharacterArray variableLongSubclass:#FourByteString
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Collections-Text'
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!FourByteString class methodsFor:'documentation'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2004 by eXept Software AG
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    FourByteStrings are like strings, but storing 32bits per character.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    The integration of them into the system is not completed ....
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    [author:]
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
        Claus Gittinger
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    [see also:]
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        Text TwoByteString UnicodeEncodedString
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
        StringCollection
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
!FourByteString class methodsFor:'initialization'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
initialize
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    "initialize the class - private"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    self flags:(Behavior flagLongs)
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    "
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
     FourByteString initialize
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    "
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    "Modified: 22.4.1996 / 16:14:14 / cg"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!FourByteString class methodsFor:'instance creation'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
basicNew:anInteger
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    "return a new empty string with anInteger characters"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    ^ (super basicNew:anInteger) atAllPut:(Character space)
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    "Modified: 26.2.1996 / 14:38:47 / cg"
3533
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    75
!
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    76
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    77
uninitializedNew:anInteger
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    78
    "return a new empty string with anInteger characters"
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    79
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    80
    ^ super basicNew:anInteger
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    81
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    82
    "
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    83
        self uninitializedNew:10
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
    84
    "
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
!FourByteString methodsFor:'accessing'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
basicAt:index
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    "return the character at position index, an Integer
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
     - reimplemented here since we return 32-bit characters"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    |val|
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    val := super basicAt:index.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    ^ Character value:val
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
basicAt:index put:aCharacter
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "store the argument, aCharacter at position index, an Integer.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
     Returns aCharacter (sigh).
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
     - reimplemented here since we store 32-bit characters"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    |val|
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
1415
3ef6a2c42611 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 1404
diff changeset
   106
    val := aCharacter codePoint.
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    super basicAt:index put:val.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    ^ aCharacter
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   111
!FourByteString methodsFor:'filling and replacing'!
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   112
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   113
from:start to:stop put:aCharacter
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   114
    "fill part of the receiver with aCharacter.
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   115
     - reimplemented here for speed"
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   116
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   117
%{  /* NOCONTEXT */
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   118
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   119
    REGISTER int count;
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   120
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   121
    // fprintf(stderr, "fill32...\n");
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   122
    if (__isCharacter(aCharacter)
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   123
     && __bothSmallInteger(start, stop)) {
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   124
        OBJ cls;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   125
        int len, index1, index2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   126
        REGISTER unsigned int *dstp;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   127
        
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   128
        len = __unicode32StringSize(self);
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   129
        index1 = __intVal(start);
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   130
        index2 = __intVal(stop);
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   131
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   132
        dstp = __unicode32StringVal(self) + index1 - 1;
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   133
        if (((cls = __qClass(self)) == Unicode32String)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   134
         || (__OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) == 0)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   135
            REGISTER unsigned charValue = __intVal(__characterVal(aCharacter));
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   136
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   137
            if (((unsigned)charValue <= 0x0FFFFFFF)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   138
             && (index1 <= index2)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   139
             && (index1 > 0)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   140
             && (index2 <= len)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   141
                count = index2 - index1 + 1;
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   142
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   143
#if (__POINTER_SIZE__ == 8)
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   144
                {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   145
                    unsigned INT v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   146
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   147
                    v2 = (charValue << 32) | charValue;
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   148
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   149
                    /* fill unaligned part */
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   150
                    while ((count > 0) && (((unsigned INT)dstp & 7) != 0)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   151
                        *dstp++ = charValue;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   152
                        count--;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   153
                    }
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   154
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   155
                    /* fill aligned part */
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   156
                    // TODO: use SSE instructions, if possible
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   157
                    while (count >= 16) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   158
                        ((unsigned INT *)dstp)[0] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   159
                        ((unsigned INT *)dstp)[1] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   160
                        ((unsigned INT *)dstp)[2] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   161
                        ((unsigned INT *)dstp)[3] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   162
                        ((unsigned INT *)dstp)[4] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   163
                        ((unsigned INT *)dstp)[5] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   164
                        ((unsigned INT *)dstp)[6] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   165
                        ((unsigned INT *)dstp)[7] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   166
                        dstp += 16;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   167
                        count -= 16;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   168
                    }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   169
                    if (count >= 8) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   170
                        ((unsigned INT *)dstp)[0] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   171
                        ((unsigned INT *)dstp)[1] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   172
                        ((unsigned INT *)dstp)[2] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   173
                        ((unsigned INT *)dstp)[3] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   174
                        dstp += 8;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   175
                        count -= 8;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   176
                    }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   177
                    if (count >= 4) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   178
                        ((unsigned INT *)dstp)[0] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   179
                        ((unsigned INT *)dstp)[1] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   180
                        dstp += 4;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   181
                        count -= 4;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   182
                    }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   183
                    if (count >= 2) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   184
                        ((unsigned INT *)dstp)[0] = v2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   185
                        dstp += 2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   186
                        count -= 2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   187
                    }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   188
                    if (count > 0) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   189
                        *dstp = charValue;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   190
                    }
4922
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   191
                }
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   192
#else // not 64bit
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   193
                while (count >= 8) {
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   194
                    dstp[0] = dstp[1] = dstp[2] = dstp[3] =
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   195
                    dstp[4] = dstp[5] = dstp[6] = dstp[7] = charValue;
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   196
                    dstp += 8;
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   197
                    count -= 8;
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   198
                }
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   199
                while (count--) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   200
                    *dstp++ = charValue;
4922
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   201
                }
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   202
#endif /* 64bit */
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   203
                RETURN (self);
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   204
            }
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   205
        }
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   206
    }
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   207
%}.
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   208
    "
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   209
     fall back in case of non-integer index or out-of-bound index/value;
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   210
     will eventually lead to an out-of-bound signal raise
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   211
    "
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   212
    ^ super from:start to:stop put:aCharacter
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   213
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   214
    "
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   215
     (Unicode16String new:10) from:1 to:10 put:$a
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   216
     (Unicode16String new:20) from:10 to:20 put:$b
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   217
     (Unicode16String new:20) from:1 to:10 put:$c
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   218
     (Unicode16String new:20) from:1 to:10 put:$c 
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   219
     (Unicode16String new:100) from:2 to:99 put:$c 
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   220
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   221
     (Unicode16String new:10) from:0 to:9 put:$a
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   222
     (Unicode16String new:10) from:1 to:11 put:$a
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   223
    "
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   224
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   225
    "Created: / 26-03-2019 / 11:30:51 / Claus Gittinger"
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   226
    "Modified: / 27-03-2019 / 14:10:18 / Claus Gittinger"
4922
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   227
!
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   228
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   229
replaceFrom:start to:stop with:aString startingAt:repStart
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   230
    "replace the characters starting at index start, anInteger and ending
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   231
     at stop, anInteger with characters from aString starting at repStart.
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   232
     Return the receiver.
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   233
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   234
     - reimplemented here for speed"
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   235
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   236
%{  /* NOCONTEXT */
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   237
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   238
#ifndef NO_PRIM_STRING
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   239
    if (__bothSmallInteger(start, stop)) {
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   240
        int len;
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   241
        int index1 = __intVal(start);
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   242
        int index2 = __intVal(stop);
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   243
        int count = index2 - index1 + 1;
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   244
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   245
        if (count <= 0) {
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   246
             RETURN (self);
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   247
        }
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   248
        len = __unicode32StringSize(self);
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   249
        if ((index2 <= len) && (index1 > 0)) {
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   250
            int repIndex = __intVal(repStart);
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   251
            OBJ cls;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   252
            
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   253
            if (((cls = __qClass(self)) == Unicode32String)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   254
             || (__OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) == 0)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   255
                if (__isStringLike(aString)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   256
                    int repLen = __stringSize(aString);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   257
                    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   258
                        REGISTER unsigned char *srcp = __stringVal(aString) + repIndex - 1;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   259
                        REGISTER unsigned int *dstp  = __unicode32StringVal(self) + index1 - 1;
4922
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   260
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   261
                        while (count-- > 0) {
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   262
                            *dstp++ = *srcp++;
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   263
                        }
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   264
                        RETURN (self);
4922
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   265
                    }
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   266
                } else if (__isTwoByteString(aString) || __isUnicode16String(aString)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   267
                    int repLen = __twoByteStringSize(aString);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   268
                    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   269
                        REGISTER unsigned short *srcp = __twoByteStringVal(aString) + repIndex - 1;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   270
                        REGISTER unsigned int *dstp  = __unicode32StringVal(self) + index1 - 1;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   271
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   272
                        while (count-- > 0) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   273
                            *dstp++ = *srcp++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   274
                        }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   275
                        RETURN (self);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   276
                    }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   277
                } else if (__isUnicode32String(aString)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   278
                    int repLen = __unicode32StringSize(aString);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   279
                    if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   280
                        REGISTER unsigned int *srcp  = __unicode32StringVal(aString) + repIndex - 1;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   281
                        REGISTER unsigned int *dstp = __unicode32StringVal(self) + index1 - 1;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   282
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   283
                        if (aString == self) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   284
                            /* take care of overlapping copy */
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   285
                            memmove(dstp, srcp, count*sizeof(int));
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   286
                            RETURN (self);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   287
                        }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   288
                        if (count > 5) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   289
                            memcpy(dstp, srcp, count*sizeof(int));
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   290
                        } else {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   291
                            while (count-- > 0) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   292
                                *dstp++ = *srcp++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   293
                            }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   294
                        }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   295
                        RETURN (self);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   296
                    }
4922
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   297
                }
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   298
            }
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   299
        }
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   300
    }
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   301
#endif
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   302
%}.
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   303
    "/ arrive here if any index arg is out o range, or the source is neither a string,
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   304
    "/ nor a two-byte string.
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   305
    ^ super replaceFrom:start to:stop with:aString startingAt:repStart
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   306
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   307
    "
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   308
     'hello world' asUnicode32String replaceFrom:1 to:5 with:'123456' startingAt:2
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   309
     'hello world' asUnicode32String replaceFrom:1 to:5 with:'123456' asUnicode16String startingAt:2
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   310
     'hello world' asUnicode32String replaceFrom:1 to:5 with:'123456' asUnicode32String startingAt:2
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   311
     'hello world' asUnicode32String replaceFrom:1 to:0 with:'123456' startingAt:2
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   312
     'hello' asUnicode32String replaceFrom:1 to:6 with:'123456' startingAt:2
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   313
     'hello world' asUnicode32String replaceFrom:1 to:1 with:'123456' startingAt:2
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   314
    "
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   315
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   316
    "Created: / 26-03-2019 / 12:10:26 / Claus Gittinger"
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   317
    "Modified: / 27-03-2019 / 14:11:27 / Claus Gittinger"
4920
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   318
! !
8c94a1a0ed25 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4512
diff changeset
   319
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
!FourByteString methodsFor:'queries'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
bitsPerCharacter
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
    "return the number of bits each character has.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
     Here, 32 is returned (storing quad byte characters)."
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
    ^ 32
2865
6f8b04862cc9 class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   327
!
6f8b04862cc9 class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   328
3826
63c5834d27c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3805
diff changeset
   329
bytesPerCharacter
63c5834d27c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3805
diff changeset
   330
    "return the number of bytes each character has.
63c5834d27c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3805
diff changeset
   331
     Here, 4 is returned (storing quad byte characters)."
63c5834d27c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3805
diff changeset
   332
63c5834d27c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3805
diff changeset
   333
    ^ 4
63c5834d27c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3805
diff changeset
   334
!
63c5834d27c1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3805
diff changeset
   335
2865
6f8b04862cc9 class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   336
isWideString
3805
9cb0780df5fc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3586
diff changeset
   337
    "true if I require more than one byte per character"
9cb0780df5fc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3586
diff changeset
   338
2865
6f8b04862cc9 class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 1415
diff changeset
   339
    ^ true
4923
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   340
!
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   341
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   342
occurrencesOf:aCharacter
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   343
    "count the occurrences of the argument, aCharacter in myself
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   344
      - reimplemented here for speed"
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   345
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   346
%{  /* NOCONTEXT */
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   347
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   348
    REGISTER unsigned charValue;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   349
    REGISTER INT count, limit;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   350
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   351
    if (__isCharacter(aCharacter)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   352
        limit = __unicode32StringSize(self);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   353
        count = 0;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   354
        charValue = __intVal(__characterVal(aCharacter));
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   355
        if (charValue <= 0x3FFFFFFF) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   356
            OBJ cls;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   357
            REGISTER unsigned int* cp;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   358
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   359
            cp = __unicode32StringVal(self);
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   360
            if (((cls = __qClass(self)) == Unicode32String)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   361
             || (__OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) == 0)) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   362
                /* loop unrolled and software-pipelined
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   363
                 * (gives 30-40% speedup on Intel-DUO using borland bcc55)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   364
                 */
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   365
                while (limit >= 4) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   366
                    register unsigned int c1, c2;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   367
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   368
                    c1 = cp[0];
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   369
                    limit -= 4;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   370
                    c2 = cp[1];
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   371
                    if (c1 == charValue) count++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   372
                    c1 = cp[2];
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   373
                    if (c2 == charValue) count++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   374
                    c2 = cp[3];
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   375
                    if (c1 == charValue) count++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   376
                    cp += 4;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   377
                    if (c2 == charValue) count++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   378
                }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   379
                while (limit > 0) {
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   380
                    register unsigned int c;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   381
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   382
                    c = cp[0];
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   383
                    limit--;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   384
                    if (c == charValue) count++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   385
                    cp++;
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   386
                }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   387
            }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   388
            RETURN ( __mkSmallInteger(count) );
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   389
        }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   390
    }
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   391
%}.
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   392
    ^ super occurrencesOf:aCharacter
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   393
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   394
    "
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   395
     'hello world' asUnicode32String occurrencesOf:$a
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   396
     'hello world' asUnicode32String occurrencesOf:$w
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   397
     'hello world' asUnicode32String occurrencesOf:$l
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   398
     'hello world' asUnicode32String occurrencesOf:$x
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   399
     'hello world' asUnicode32String occurrencesOf:1
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   400
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   401
     Time millisecondsToRun:[
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   402
        |s|
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   403
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   404
        s := 'abcdefghijklmn' asUnicode32String. 
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   405
        1000000 timesRepeat:[ s occurrencesOf:$x ]
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   406
     ]. 60 60 60 70 (untuned: 690 760 670)
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   407
    "
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   408
6e6fea06fff6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4922
diff changeset
   409
    "Created: / 27-03-2019 / 14:13:43 / Claus Gittinger"
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
4511
d7c52631ad33 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   412
!FourByteString methodsFor:'testing'!
d7c52631ad33 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   413
4512
0d6157b7ce6e #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4511
diff changeset
   414
isSingleByteCollection
0d6157b7ce6e #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4511
diff changeset
   415
    "return true, if the receiver has access methods for bytes;
0d6157b7ce6e #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4511
diff changeset
   416
     i.e. #at: and #at:put: accesses a byte and are equivalent to #byteAt: and byteAt:put:
0d6157b7ce6e #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4511
diff changeset
   417
     and #replaceFrom:to: is equivalent to #replaceBytesFrom:to:. 
0d6157b7ce6e #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4511
diff changeset
   418
     false is returned here since at: returns 4-byte characters and not bytes 
0d6157b7ce6e #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4511
diff changeset
   419
      - the method is redefined from UninterpretedBytes."
0d6157b7ce6e #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4511
diff changeset
   420
4511
d7c52631ad33 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   421
    ^ false
d7c52631ad33 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   422
d7c52631ad33 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   423
    "Created: / 30-08-2017 / 23:31:02 / cg"
d7c52631ad33 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   424
! !
d7c52631ad33 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 3840
diff changeset
   425
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
!FourByteString class methodsFor:'documentation'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
version
3586
a6d20359cdf4 class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 3533
diff changeset
   429
    ^ '$Header$'
4922
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   430
!
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   431
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   432
version_CVS
ff7afd151379 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
   433
    ^ '$Header$'
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
3533
1465b5fed73e class: FourByteString
Stefan Vogel <sv@exept.de>
parents: 2865
diff changeset
   436
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
FourByteString initialize!