Differences From Artifact [1f1150d009]:
- File src/OFArray.m — part of check-in [374e1a1bfa] at 2021-01-02 22:04:26 on branch trunk — Update copyright (user: js, size: 18127) [annotate] [blame] [check-ins using] [more...]
To Artifact [e8aa9a3165]:
- File
src/OFArray.m
— part of check-in
[a0fd103a0b]
at
2021-03-07 02:36:04
on branch trunk
— Style change: Allow more than 1 argument per line
This is only migrating some places, others will be migrated as they are
touched. (user: js, size: 18007) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
191 192 193 194 195 196 197 | - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); | | < | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [self initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments |
︙ | ︙ | |||
238 239 240 241 242 243 244 | - (id const *)objects { size_t count = self.count; id *buffer = of_alloc(count, sizeof(id)); @try { | | < | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | - (id const *)objects { size_t count = self.count; id *buffer = of_alloc(count, sizeof(id)); @try { [self getObjects: buffer inRange: of_range(0, count)]; return [[OFData dataWithItemsNoCopy: buffer count: count itemSize: sizeof(id) freeWhenDone: true] items]; } @catch (id e) { free(buffer); |
︙ | ︙ | |||
294 295 296 297 298 299 300 | } [ret makeImmutable]; return ret; } | | < | < | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | } [ret makeImmutable]; return ret; } - (void)setValue: (id)value forKey: (OFString *)key { for (id object in self) [object setValue: value forKey: key]; } - (size_t)indexOfObject: (id)object { size_t i = 0; if (object == nil) |
︙ | ︙ | |||
374 375 376 377 378 379 380 | id *buffer; if (range.length > SIZE_MAX - range.location || range.location + range.length < self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) | | < | < | < | 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | id *buffer; if (range.length > SIZE_MAX - range.location || range.location + range.length < self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) return [OFSubarray arrayWithArray: self range: range]; buffer = of_alloc(range.length, sizeof(*buffer)); @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer count: range.length]; } @finally { free(buffer); } return ret; } |
︙ | ︙ | |||
536 537 538 539 540 541 542 | return @"()"; pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { [ret prependString: @"(\n"]; | | < | 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | return @"()"; pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { [ret prependString: @"(\n"]; [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)"]; } @catch (id e) { [ret release]; @throw e; } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
580 581 582 583 584 585 586 | objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { | | < | < | 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (int)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *)of_JSONRepresentationWithOptions: (int)options depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"["]; void *pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
665 666 667 668 669 670 671 | uint8_t tmp = 0x90 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDC; uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count); [data addItem: &type]; | | < | < | < | 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | uint8_t tmp = 0x90 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDC; uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDD; uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); i = 0; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); OFData *child; i++; child = [object messagePackRepresentation]; [data addItems: child.items count: child.count]; objc_autoreleasePoolPop(pool2); } assert(i == count); [data makeImmutable]; |
︙ | ︙ | |||
712 713 714 715 716 717 718 | [object performSelector: selector]; } - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object { for (id objectIter in self) | | < < < < < | < < < < | < < < < < < | < | 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | [object performSelector: selector]; } - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object { for (id objectIter in self) [objectIter performSelector: selector withObject: object]; } - (OFArray *)sortedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sort]; [new makeImmutable]; return new; } - (OFArray *)sortedArrayUsingSelector: (SEL)selector options: (int)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingSelector: selector options: options]; [new makeImmutable]; return new; } #ifdef OF_HAVE_BLOCKS - (OFArray *)sortedArrayUsingComparator: (of_comparator_t)comparator options: (int)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingComparator: comparator options: options]; [new makeImmutable]; return new; } #endif - (OFArray *)reversedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; [new reverse]; [new makeImmutable]; return new; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state objects: (id *)objects count: (int)count { of_range_t range = of_range(state->state, count); if (range.length > SIZE_MAX - range.location) @throw [OFOutOfRangeException exception]; if (range.location + range.length > self.count) range.length = self.count - range.location; [self getObjects: objects inRange: range]; if (range.location + range.length > ULONG_MAX) @throw [OFOutOfRangeException exception]; state->state = (unsigned long)(range.location + range.length); state->itemsPtr = objects; state->mutationsPtr = (unsigned long *)self; |
︙ | ︙ | |||
820 821 822 823 824 825 826 | { OFMutableArray *ret; if (object == nil) @throw [OFInvalidArgumentException exception]; ret = [[self mutableCopy] autorelease]; | < < < < | < | 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | { OFMutableArray *ret; if (object == nil) @throw [OFInvalidArgumentException exception]; ret = [[self mutableCopy] autorelease]; [ret addObject: object]; [ret makeImmutable]; return ret; } - (OFArray *)arrayByAddingObjectsFromArray: (OFArray *)array { OFMutableArray *ret = [[self mutableCopy] autorelease]; [ret addObjectsFromArray: array]; [ret makeImmutable]; return ret; } - (OFArray *)arrayByRemovingObject: (id)object { OFMutableArray *ret = [[self mutableCopy] autorelease]; [ret removeObject: object]; [ret makeImmutable]; return ret; } #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = self.count; id *tmp = of_alloc(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); }]; ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { free(tmp); } return ret; } |
︙ | ︙ | |||
884 885 886 887 888 889 890 | [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { if (block(object, idx)) tmp[i++] = object; }]; | | < | 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { if (block(object, idx)) tmp[i++] = object; }]; ret = [OFArray arrayWithObjects: tmp count: i]; } @finally { free(tmp); } return ret; } |
︙ | ︙ |