Differences From Artifact [cb57991be9]:
- File src/OFMutableUTF8String.m — part of check-in [b6cb3addd0] at 2020-06-28 15:03:23 on branch trunk — Use OF_DIRECT(_MEMBERS) where appropriate (user: js, size: 20325) [annotate] [blame] [check-ins using] [more...]
To Artifact [77a77e4c53]:
- File
src/OFMutableUTF8String.m
— part of check-in
[0ddaac3f5b]
at
2020-11-05 00:24:29
on branch trunk
— Avoid -[allocMemoryWithSize:] for temporary memory
-[allocMemoryWithSize:] has book keeping overhead that is unnecessary
for temporary memory. (user: js, size: 20195) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
101 102 103 104 105 106 107 | _s->cString[i] = t; } return; } unicodeLen = self.length; | | < | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | _s->cString[i] = t; } return; } unicodeLen = self.length; unicodeString = of_malloc(unicodeLen, sizeof(of_unichar_t)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { const of_unichar_t *const *table; size_t tableSize; |
︙ | ︙ | |||
125 126 127 128 129 130 131 | tableSize = middleTableSize; } cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | tableSize = middleTableSize; } cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { free(unicodeString); @throw [OFInvalidEncodingException exception]; } isStart = of_ascii_isspace(c); if (c >> 8 < tableSize) { of_unichar_t tc = table[c >> 8][c & 0xFF]; |
︙ | ︙ | |||
148 149 150 151 152 153 154 | else if (c < 0x800) newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { | | | | | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | else if (c < 0x800) newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { free(unicodeString); @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { newCString = [self allocMemoryWithSize: newCStringLength + 1]; } @catch (id e) { free(unicodeString); @throw e; } j = 0; for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = of_string_utf8_encode(unicodeString[i], newCString + j)) == 0) { free(unicodeString); [self freeMemory: newCString]; @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; free(unicodeString); [self freeMemory: _s->cString]; _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; /* |
︙ | ︙ | |||
381 382 383 384 385 386 387 | } else _s->isUTF8 = true; } - (void)appendCharacters: (const of_unichar_t *)characters length: (size_t)length { | | < | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | } else _s->isUTF8 = true; } - (void)appendCharacters: (const of_unichar_t *)characters length: (size_t)length { char *tmp = of_malloc((length * 4) + 1, 1); @try { size_t j = 0; bool isUTF8 = false; for (size_t i = 0; i < length; i++) { size_t len = of_string_utf8_encode(characters[i], tmp + j); |
︙ | ︙ | |||
414 415 416 417 418 419 420 | _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { | | | 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { free(tmp); } } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; |
︙ | ︙ |