FourByteString.st
changeset 4922 ff7afd151379
parent 4920 8c94a1a0ed25
child 4923 6e6fea06fff6
equal deleted inserted replaced
4921:e5f2b1b5a28d 4922:ff7afd151379
   138         }
   138         }
   139 
   139 
   140         charValue = __intVal(__characterVal(aCharacter));
   140         charValue = __intVal(__characterVal(aCharacter));
   141         if (((unsigned)charValue <= 0x0FFFFFFF)
   141         if (((unsigned)charValue <= 0x0FFFFFFF)
   142          && (index1 <= index2)
   142          && (index1 <= index2)
   143          && (index1 > 0)) {
   143          && (index1 > 0)
   144             if (index2 <= len) {
   144          && (index2 <= len)) {
   145                 count = index2 - index1 + 1;
   145             count = index2 - index1 + 1;
   146 
   146 
   147 #if (__POINTER_SIZE__ == 8)
   147 #if (__POINTER_SIZE__ == 8)
   148                 {
   148             {
   149                     INT v2;
   149                 INT v2;
   150 
   150 
   151                     v2 = (charValue << 32) | charValue;
   151                 v2 = (charValue << 32) | charValue;
   152 
   152 
   153                     /* fill unaligned part */
   153                 /* fill unaligned part */
   154                     while ((count > 0) && (((unsigned INT)dstp & 7) != 0)) {
   154                 while ((count > 0) && (((unsigned INT)dstp & 7) != 0)) {
   155                         *dstp++ = charValue;
   155                     *dstp++ = charValue;
   156                         count--;
   156                     count--;
   157                     }
   157                 }
   158 
   158 
   159                     /* fill aligned part */
   159                 /* fill aligned part */
   160                     while (count >= 8) {
       
   161                         ((unsigned INT *)dstp)[0] = v2;
       
   162                         ((unsigned INT *)dstp)[1] = v2;
       
   163                         ((unsigned INT *)dstp)[2] = v2;
       
   164                         ((unsigned INT *)dstp)[3] = v2;
       
   165                         dstp += 8;
       
   166                         count -= 8;
       
   167                     }
       
   168                     /* fill aligned part */
       
   169                     while (count >= 2) {
       
   170                         ((unsigned INT *)dstp)[0] = v2;
       
   171                         dstp += 2;
       
   172                         count -= 2;
       
   173                     }
       
   174 
       
   175                     /* fill rest */
       
   176                     while (count > 0) {
       
   177                         *dstp++ = charValue;
       
   178                         count--;
       
   179                     }
       
   180                     RETURN (self);
       
   181                 }
       
   182 #endif /* 64bit */
       
   183 
       
   184                 while (count >= 8) {
   160                 while (count >= 8) {
   185                     dstp[0] = dstp[1] = dstp[2] = dstp[3] =
   161                     ((unsigned INT *)dstp)[0] = v2;
   186                     dstp[4] = dstp[5] = dstp[6] = dstp[7] = charValue;
   162                     ((unsigned INT *)dstp)[1] = v2;
       
   163                     ((unsigned INT *)dstp)[2] = v2;
       
   164                     ((unsigned INT *)dstp)[3] = v2;
   187                     dstp += 8;
   165                     dstp += 8;
   188                     count -= 8;
   166                     count -= 8;
   189                 }
   167                 }
   190                 while (count--) {
   168                 while (count >= 2) {
       
   169                     ((unsigned INT *)dstp)[0] = v2;
       
   170                     dstp += 2;
       
   171                     count -= 2;
       
   172                 }
       
   173 
       
   174                 /* fill rest */
       
   175                 while (count > 0) {
   191                     *dstp++ = charValue;
   176                     *dstp++ = charValue;
   192                 }
   177                     count--;
   193                 RETURN (self);
   178                 }
   194             }
   179             }
       
   180 #else // not 64bit
       
   181             while (count >= 8) {
       
   182                 dstp[0] = dstp[1] = dstp[2] = dstp[3] =
       
   183                 dstp[4] = dstp[5] = dstp[6] = dstp[7] = charValue;
       
   184                 dstp += 8;
       
   185                 count -= 8;
       
   186             }
       
   187             while (count--) {
       
   188                 *dstp++ = charValue;
       
   189             }
       
   190 #endif /* 64bit */
       
   191             RETURN (self);
   195         }
   192         }
   196     }
   193     }
   197 %}.
   194 %}.
   198     "
   195     "
   199      fall back in case of non-integer index or out-of-bound index/value;
   196      fall back in case of non-integer index or out-of-bound index/value;
   211      (Unicode16String new:10) from:0 to:9 put:$a
   208      (Unicode16String new:10) from:0 to:9 put:$a
   212      (Unicode16String new:10) from:1 to:11 put:$a
   209      (Unicode16String new:10) from:1 to:11 put:$a
   213     "
   210     "
   214 
   211 
   215     "Created: / 26-03-2019 / 11:30:51 / Claus Gittinger"
   212     "Created: / 26-03-2019 / 11:30:51 / Claus Gittinger"
       
   213 !
       
   214 
       
   215 replaceFrom:start to:stop with:aString startingAt:repStart
       
   216     "replace the characters starting at index start, anInteger and ending
       
   217      at stop, anInteger with characters from aString starting at repStart.
       
   218      Return the receiver.
       
   219 
       
   220      - reimplemented here for speed"
       
   221 
       
   222 %{  /* NOCONTEXT */
       
   223 
       
   224 #ifndef NO_PRIM_STRING
       
   225     if (__bothSmallInteger(start, stop)) {
       
   226         int len;
       
   227         int index1 = __intVal(start);
       
   228         int index2 = __intVal(stop);
       
   229         int count = index2 - index1 + 1;
       
   230 
       
   231         if (count <= 0) {
       
   232              RETURN (self);
       
   233         }
       
   234         len = __unicode32StringSize(self);
       
   235         if ((index2 <= len) && (index1 > 0)) {
       
   236             int repIndex = __intVal(repStart);
       
   237 
       
   238             if (__isStringLike(aString)) {
       
   239                 int repLen = __stringSize(aString);
       
   240                 if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
       
   241                     REGISTER unsigned char *srcp = __stringVal(aString) + repIndex - 1;
       
   242                     REGISTER unsigned int *dstp  = __unicode32StringVal(self) + index1 - 1;
       
   243 
       
   244                     while (count-- > 0) {
       
   245                         *dstp++ = *srcp++;
       
   246                     }
       
   247                     RETURN (self);
       
   248                 }
       
   249             } else if (__isTwoByteString(aString) || __isUnicode16String(aString)) {
       
   250                 int repLen = __twoByteStringSize(aString);
       
   251                 if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
       
   252                     REGISTER unsigned short *srcp = __twoByteStringVal(aString) + repIndex - 1;
       
   253                     REGISTER unsigned int *dstp  = __unicode32StringVal(self) + index1 - 1;
       
   254 
       
   255                     while (count-- > 0) {
       
   256                         *dstp++ = *srcp++;
       
   257                     }
       
   258                     RETURN (self);
       
   259                 }
       
   260             } else if (__isUnicode32String(aString)) {
       
   261                 int repLen = __unicode32StringSize(aString);
       
   262                 if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) {
       
   263                     REGISTER unsigned int *srcp  = __unicode32StringVal(aString) + repIndex - 1;
       
   264                     REGISTER unsigned int *dstp = __unicode32StringVal(self) + index1 - 1;
       
   265 
       
   266                     if (aString == self) {
       
   267                         /* take care of overlapping copy */
       
   268                         memmove(dstp, srcp, count*sizeof(int));
       
   269                         RETURN (self);
       
   270                     }
       
   271                     if (count > 5) {
       
   272                         memcpy(dstp, srcp, count*sizeof(int));
       
   273                     } else {
       
   274                         while (count-- > 0) {
       
   275                             *dstp++ = *srcp++;
       
   276                         }
       
   277                     }
       
   278                     RETURN (self);
       
   279                 }
       
   280             }
       
   281         }
       
   282     }
       
   283 #endif
       
   284 %}.
       
   285     "/ arrive here if any index arg is out o range, or the source is neither a string,
       
   286     "/ nor a two-byte string.
       
   287     ^ super replaceFrom:start to:stop with:aString startingAt:repStart
       
   288 
       
   289     "
       
   290      'hello world' asUnicode32String replaceFrom:1 to:5 with:'123456' startingAt:2
       
   291      'hello world' asUnicode32String replaceFrom:1 to:5 with:'123456' asUnicode16String startingAt:2
       
   292      'hello world' asUnicode32String replaceFrom:1 to:5 with:'123456' asUnicode32String startingAt:2
       
   293      'hello world' asUnicode32String replaceFrom:1 to:0 with:'123456' startingAt:2
       
   294      'hello' asUnicode32String replaceFrom:1 to:6 with:'123456' startingAt:2
       
   295      'hello world' asUnicode32String replaceFrom:1 to:1 with:'123456' startingAt:2
       
   296     "
       
   297 
       
   298     "Created: / 26-03-2019 / 12:10:26 / Claus Gittinger"
   216 ! !
   299 ! !
   217 
   300 
   218 !FourByteString methodsFor:'queries'!
   301 !FourByteString methodsFor:'queries'!
   219 
   302 
   220 bitsPerCharacter
   303 bitsPerCharacter
   253 
   336 
   254 !FourByteString class methodsFor:'documentation'!
   337 !FourByteString class methodsFor:'documentation'!
   255 
   338 
   256 version
   339 version
   257     ^ '$Header$'
   340     ^ '$Header$'
       
   341 !
       
   342 
       
   343 version_CVS
       
   344     ^ '$Header$'
   258 ! !
   345 ! !
   259 
   346 
   260 
   347 
   261 FourByteString initialize!
   348 FourByteString initialize!