Differences From Artifact [20a79e42c1]:
- File
src/OFData.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: 14753) [annotate] [blame] [check-ins using]
To Artifact [f4f38100bd]:
- File src/OFData.m — part of check-in [1a70abc65d] at 2020-11-06 01:11:51 on branch trunk — OF*Data: Avoid -[allocMemoryWithSize:] (user: js, size: 14754) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
129 130 131 132 133 134 135 | { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; | | < > | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _items = of_malloc(count, itemSize); _itemSize = itemSize; _count = count; _freeWhenDone = true; memcpy(_items, items, count * itemSize); } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | exceptionWithURL: URL]; stream = [URLHandler openItemAtURL: URL mode: @"r"]; _itemSize = 1; _count = 0; pageSize = [OFSystemInfo pageSize]; buffer = of_malloc(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; if (SIZE_MAX - _count < length) @throw [OFOutOfRangeException exception]; | > < | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | exceptionWithURL: URL]; stream = [URLHandler openItemAtURL: URL mode: @"r"]; _itemSize = 1; _count = 0; _freeWhenDone = true; pageSize = [OFSystemInfo pageSize]; buffer = of_malloc(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; if (SIZE_MAX - _count < length) @throw [OFOutOfRangeException exception]; _items = of_realloc(_items, _count + length, 1); memcpy(_items + _count, buffer, length); _count += length; } } @finally { free(buffer); } |
︙ | ︙ | |||
288 289 290 291 292 293 294 | const char *cString; if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; | | > | 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | const char *cString; if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; _items = of_malloc(count, 1); _itemSize = 1; _count = count; _freeWhenDone = true; cString = [string cStringWithEncoding: OF_STRING_ENCODING_ASCII]; for (size_t i = 0; i < count; i++) { uint8_t c1 = cString[2 * i]; uint8_t c2 = cString[2 * i + 1]; |
︙ | ︙ |