Differences From Artifact [d431a67a01]:
- File src/OFDataArray.m — part of check-in [e68229ff3b] at 2012-06-06 12:23:23 on branch trunk — Add a missing check in OFDataArray. (user: js, size: 12848) [annotate] [blame] [check-ins using]
To Artifact [490fab954b]:
- File
src/OFDataArray.m
— part of check-in
[d5ddb2cb48]
at
2012-06-06 13:09:08
on branch trunk
— Rework OFDataArray API.
Also adds more checks. (user: js, size: 12312) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
109 110 111 112 113 114 115 | char *buffer = [self allocMemoryWithSize: of_pagesize]; while (![file isAtEndOfStream]) { size_t length; length = [file readNBytes: of_pagesize intoBuffer: buffer]; | < | > | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | char *buffer = [self allocMemoryWithSize: of_pagesize]; while (![file isAtEndOfStream]) { size_t length; length = [file readNBytes: of_pagesize intoBuffer: buffer]; [self addItemsFromCArray: buffer count: length]; } [self freeMemory: buffer]; } @finally { [file release]; } } @catch (id e) { |
︙ | ︙ | |||
261 262 263 264 265 266 267 | ofSize: itemSize]; memcpy(data + count * itemSize, item, itemSize); count++; } | | | < | | > < | > < | | > | < | | | < < < < < < < < < | < < < < < | < < | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | ofSize: itemSize]; memcpy(data + count * itemSize, item, itemSize); count++; } - (void)insertItem: (const void*)item atIndex: (size_t)index { [self insertItemsFromCArray: item atIndex: index count: 1]; } - (void)addItemsFromCArray: (const void*)cArray count: (size_t)nItems { if (nItems > SIZE_MAX - count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data toNItems: count + nItems ofSize: itemSize]; memcpy(data + count * itemSize, cArray, nItems * itemSize); count += nItems; } - (void)insertItemsFromCArray: (const void*)cArray atIndex: (size_t)index count: (size_t)nItems { if (nItems > SIZE_MAX - count || index > count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data toNItems: count + nItems ofSize: itemSize]; memmove(data + (index + nItems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, cArray, nItems * itemSize); count += nItems; } - (void)removeItemAtIndex: (size_t)index { [self removeItemsInRange: of_range(index, 1)]; } - (void)removeItemsInRange: (of_range_t)range { if (range.start + range.length > count) @throw [OFOutOfRangeException exceptionWithClass: isa]; memmove(data + range.start * itemSize, data + (range.start + range.length) * itemSize, (count - range.start - range.length) * itemSize); count -= range.length; @try { data = [self resizeMemory: data toNItems: count ofSize: itemSize]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } |
︙ | ︙ | |||
369 370 371 372 373 374 375 | count = 0; } - copy { OFDataArray *copy = [[isa alloc] initWithItemSize: itemSize]; | < | > | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | count = 0; } - copy { OFDataArray *copy = [[isa alloc] initWithItemSize: itemSize]; [copy addItemsFromCArray: data count: count]; return copy; } - (BOOL)isEqual: (id)object { OFDataArray *otherDataArray; |
︙ | ︙ | |||
501 502 503 504 505 506 507 | memcpy(data + count * itemSize, item, itemSize); count++; size = newSize; } | < | > < | | > | > | | < < < | < < < < < | < < < < | < < < < < | | 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | memcpy(data + count * itemSize, item, itemSize); count++; size = newSize; } - (void)addItemsFromCArray: (const void*)cArray count: (size_t)nItems { size_t newSize, lastPageByte; if (nItems > SIZE_MAX - count || count + nItems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toSize: newSize]; memcpy(data + count * itemSize, cArray, nItems * itemSize); count += nItems; size = newSize; } - (void)insertItemsFromCArray: (const void*)cArray atIndex: (size_t)index count: (size_t)nItems { size_t newSize, lastPageByte; if (nItems > SIZE_MAX - count || index > count || count + nItems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toSize: newSize]; memmove(data + (index + nItems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, cArray, nItems * itemSize); count += nItems; size = newSize; } - (void)removeItemsInRange: (of_range_t)range { size_t newSize, lastPageByte; if (range.start + range.length > count) @throw [OFOutOfRangeException exceptionWithClass: isa]; memmove(data + range.start * itemSize, data + (range.start + range.length) * itemSize, (count - range.start - range.length) * itemSize); count -= range.length; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data toSize: newSize]; size = newSize; |
︙ | ︙ |