Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: third_party/protobuf/objectivec/GPBArray.m

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2015 Google Inc. All rights reserved. 2 // Copyright 2015 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 //%@implementation GPB##NAME##Array { 68 //%@implementation GPB##NAME##Array {
69 //% @package 69 //% @package
70 //% TYPE *_values; 70 //% TYPE *_values;
71 //% NSUInteger _count; 71 //% NSUInteger _count;
72 //% NSUInteger _capacity; 72 //% NSUInteger _capacity;
73 //%} 73 //%}
74 //% 74 //%
75 //%@synthesize count = _count; 75 //%@synthesize count = _count;
76 //% 76 //%
77 //%+ (instancetype)array { 77 //%+ (instancetype)array {
78 //% return [[[self alloc] initWithValues:NULL count:0] autorelease]; 78 //% return [[[self alloc] init] autorelease];
79 //%} 79 //%}
80 //% 80 //%
81 //%+ (instancetype)arrayWithValue:(TYPE)value { 81 //%+ (instancetype)arrayWithValue:(TYPE)value {
82 //% // Cast is needed so the compiler knows what class we are invoking initWith Values: on to get 82 //% // Cast is needed so the compiler knows what class we are invoking initWith Values: on to get
83 //% // the type correct. 83 //% // the type correct.
84 //% return [[(GPB##NAME##Array*)[self alloc] initWithValues:&value count:1] aut orelease]; 84 //% return [[(GPB##NAME##Array*)[self alloc] initWithValues:&value count:1] aut orelease];
85 //%} 85 //%}
86 //% 86 //%
87 //%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array { 87 //%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array {
88 //% return [[(GPB##NAME##Array*)[self alloc] initWithValueArray:array] autorele ase]; 88 //% return [[(GPB##NAME##Array*)[self alloc] initWithValueArray:array] autorele ase];
89 //%} 89 //%}
90 //% 90 //%
91 //%+ (instancetype)arrayWithCapacity:(NSUInteger)count { 91 //%+ (instancetype)arrayWithCapacity:(NSUInteger)count {
92 //% return [[[self alloc] initWithCapacity:count] autorelease]; 92 //% return [[[self alloc] initWithCapacity:count] autorelease];
93 //%} 93 //%}
94 //% 94 //%
95 //%- (instancetype)init { 95 //%- (instancetype)init {
96 //% return [self initWithValues:NULL count:0]; 96 //% self = [super init];
97 //% // No work needed;
98 //% return self;
97 //%} 99 //%}
98 //% 100 //%
99 //%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array { 101 //%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array {
100 //% return [self initWithValues:array->_values count:array->_count]; 102 //% return [self initWithValues:array->_values count:array->_count];
101 //%} 103 //%}
102 //% 104 //%
103 //%- (instancetype)initWithValues:(const TYPE [])values count:(NSUInteger)count { 105 //%- (instancetype)initWithValues:(const TYPE [])values count:(NSUInteger)count {
104 //% self = [super init]; 106 //% self = [self init];
105 //% if (self) { 107 //% if (self) {
106 //% if (count && values) { 108 //% if (count && values) {
107 //% _values = malloc(count * sizeof(TYPE)); 109 //% _values = reallocf(_values, count * sizeof(TYPE));
108 //% if (values != NULL) { 110 //% if (_values != NULL) {
109 //% _capacity = count; 111 //% _capacity = count;
110 //% memcpy(_values, values, count * sizeof(TYPE)); 112 //% memcpy(_values, values, count * sizeof(TYPE));
111 //% _count = count; 113 //% _count = count;
112 //% } else { 114 //% } else {
113 //% [self release]; 115 //% [self release];
114 //% [NSException raise:NSMallocException 116 //% [NSException raise:NSMallocException
115 //% format:@"Failed to allocate %lu bytes", 117 //% format:@"Failed to allocate %lu bytes",
116 //% (unsigned long)(count * sizeof(TYPE))]; 118 //% (unsigned long)(count * sizeof(TYPE))];
117 //% } 119 //% }
118 //% } 120 //% }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 @implementation GPBInt32Array { 294 @implementation GPBInt32Array {
293 @package 295 @package
294 int32_t *_values; 296 int32_t *_values;
295 NSUInteger _count; 297 NSUInteger _count;
296 NSUInteger _capacity; 298 NSUInteger _capacity;
297 } 299 }
298 300
299 @synthesize count = _count; 301 @synthesize count = _count;
300 302
301 + (instancetype)array { 303 + (instancetype)array {
302 return [[[self alloc] initWithValues:NULL count:0] autorelease]; 304 return [[[self alloc] init] autorelease];
303 } 305 }
304 306
305 + (instancetype)arrayWithValue:(int32_t)value { 307 + (instancetype)arrayWithValue:(int32_t)value {
306 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get 308 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get
307 // the type correct. 309 // the type correct.
308 return [[(GPBInt32Array*)[self alloc] initWithValues:&value count:1] autorelea se]; 310 return [[(GPBInt32Array*)[self alloc] initWithValues:&value count:1] autorelea se];
309 } 311 }
310 312
311 + (instancetype)arrayWithValueArray:(GPBInt32Array *)array { 313 + (instancetype)arrayWithValueArray:(GPBInt32Array *)array {
312 return [[(GPBInt32Array*)[self alloc] initWithValueArray:array] autorelease]; 314 return [[(GPBInt32Array*)[self alloc] initWithValueArray:array] autorelease];
313 } 315 }
314 316
315 + (instancetype)arrayWithCapacity:(NSUInteger)count { 317 + (instancetype)arrayWithCapacity:(NSUInteger)count {
316 return [[[self alloc] initWithCapacity:count] autorelease]; 318 return [[[self alloc] initWithCapacity:count] autorelease];
317 } 319 }
318 320
319 - (instancetype)init { 321 - (instancetype)init {
320 return [self initWithValues:NULL count:0]; 322 self = [super init];
323 // No work needed;
324 return self;
321 } 325 }
322 326
323 - (instancetype)initWithValueArray:(GPBInt32Array *)array { 327 - (instancetype)initWithValueArray:(GPBInt32Array *)array {
324 return [self initWithValues:array->_values count:array->_count]; 328 return [self initWithValues:array->_values count:array->_count];
325 } 329 }
326 330
327 - (instancetype)initWithValues:(const int32_t [])values count:(NSUInteger)count { 331 - (instancetype)initWithValues:(const int32_t [])values count:(NSUInteger)count {
328 self = [super init]; 332 self = [self init];
329 if (self) { 333 if (self) {
330 if (count && values) { 334 if (count && values) {
331 _values = malloc(count * sizeof(int32_t)); 335 _values = reallocf(_values, count * sizeof(int32_t));
332 if (values != NULL) { 336 if (_values != NULL) {
333 _capacity = count; 337 _capacity = count;
334 memcpy(_values, values, count * sizeof(int32_t)); 338 memcpy(_values, values, count * sizeof(int32_t));
335 _count = count; 339 _count = count;
336 } else { 340 } else {
337 [self release]; 341 [self release];
338 [NSException raise:NSMallocException 342 [NSException raise:NSMallocException
339 format:@"Failed to allocate %lu bytes", 343 format:@"Failed to allocate %lu bytes",
340 (unsigned long)(count * sizeof(int32_t))]; 344 (unsigned long)(count * sizeof(int32_t))];
341 } 345 }
342 } 346 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 @implementation GPBUInt32Array { 541 @implementation GPBUInt32Array {
538 @package 542 @package
539 uint32_t *_values; 543 uint32_t *_values;
540 NSUInteger _count; 544 NSUInteger _count;
541 NSUInteger _capacity; 545 NSUInteger _capacity;
542 } 546 }
543 547
544 @synthesize count = _count; 548 @synthesize count = _count;
545 549
546 + (instancetype)array { 550 + (instancetype)array {
547 return [[[self alloc] initWithValues:NULL count:0] autorelease]; 551 return [[[self alloc] init] autorelease];
548 } 552 }
549 553
550 + (instancetype)arrayWithValue:(uint32_t)value { 554 + (instancetype)arrayWithValue:(uint32_t)value {
551 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get 555 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get
552 // the type correct. 556 // the type correct.
553 return [[(GPBUInt32Array*)[self alloc] initWithValues:&value count:1] autorele ase]; 557 return [[(GPBUInt32Array*)[self alloc] initWithValues:&value count:1] autorele ase];
554 } 558 }
555 559
556 + (instancetype)arrayWithValueArray:(GPBUInt32Array *)array { 560 + (instancetype)arrayWithValueArray:(GPBUInt32Array *)array {
557 return [[(GPBUInt32Array*)[self alloc] initWithValueArray:array] autorelease]; 561 return [[(GPBUInt32Array*)[self alloc] initWithValueArray:array] autorelease];
558 } 562 }
559 563
560 + (instancetype)arrayWithCapacity:(NSUInteger)count { 564 + (instancetype)arrayWithCapacity:(NSUInteger)count {
561 return [[[self alloc] initWithCapacity:count] autorelease]; 565 return [[[self alloc] initWithCapacity:count] autorelease];
562 } 566 }
563 567
564 - (instancetype)init { 568 - (instancetype)init {
565 return [self initWithValues:NULL count:0]; 569 self = [super init];
570 // No work needed;
571 return self;
566 } 572 }
567 573
568 - (instancetype)initWithValueArray:(GPBUInt32Array *)array { 574 - (instancetype)initWithValueArray:(GPBUInt32Array *)array {
569 return [self initWithValues:array->_values count:array->_count]; 575 return [self initWithValues:array->_values count:array->_count];
570 } 576 }
571 577
572 - (instancetype)initWithValues:(const uint32_t [])values count:(NSUInteger)count { 578 - (instancetype)initWithValues:(const uint32_t [])values count:(NSUInteger)count {
573 self = [super init]; 579 self = [self init];
574 if (self) { 580 if (self) {
575 if (count && values) { 581 if (count && values) {
576 _values = malloc(count * sizeof(uint32_t)); 582 _values = reallocf(_values, count * sizeof(uint32_t));
577 if (values != NULL) { 583 if (_values != NULL) {
578 _capacity = count; 584 _capacity = count;
579 memcpy(_values, values, count * sizeof(uint32_t)); 585 memcpy(_values, values, count * sizeof(uint32_t));
580 _count = count; 586 _count = count;
581 } else { 587 } else {
582 [self release]; 588 [self release];
583 [NSException raise:NSMallocException 589 [NSException raise:NSMallocException
584 format:@"Failed to allocate %lu bytes", 590 format:@"Failed to allocate %lu bytes",
585 (unsigned long)(count * sizeof(uint32_t))]; 591 (unsigned long)(count * sizeof(uint32_t))];
586 } 592 }
587 } 593 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 @implementation GPBInt64Array { 788 @implementation GPBInt64Array {
783 @package 789 @package
784 int64_t *_values; 790 int64_t *_values;
785 NSUInteger _count; 791 NSUInteger _count;
786 NSUInteger _capacity; 792 NSUInteger _capacity;
787 } 793 }
788 794
789 @synthesize count = _count; 795 @synthesize count = _count;
790 796
791 + (instancetype)array { 797 + (instancetype)array {
792 return [[[self alloc] initWithValues:NULL count:0] autorelease]; 798 return [[[self alloc] init] autorelease];
793 } 799 }
794 800
795 + (instancetype)arrayWithValue:(int64_t)value { 801 + (instancetype)arrayWithValue:(int64_t)value {
796 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get 802 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get
797 // the type correct. 803 // the type correct.
798 return [[(GPBInt64Array*)[self alloc] initWithValues:&value count:1] autorelea se]; 804 return [[(GPBInt64Array*)[self alloc] initWithValues:&value count:1] autorelea se];
799 } 805 }
800 806
801 + (instancetype)arrayWithValueArray:(GPBInt64Array *)array { 807 + (instancetype)arrayWithValueArray:(GPBInt64Array *)array {
802 return [[(GPBInt64Array*)[self alloc] initWithValueArray:array] autorelease]; 808 return [[(GPBInt64Array*)[self alloc] initWithValueArray:array] autorelease];
803 } 809 }
804 810
805 + (instancetype)arrayWithCapacity:(NSUInteger)count { 811 + (instancetype)arrayWithCapacity:(NSUInteger)count {
806 return [[[self alloc] initWithCapacity:count] autorelease]; 812 return [[[self alloc] initWithCapacity:count] autorelease];
807 } 813 }
808 814
809 - (instancetype)init { 815 - (instancetype)init {
810 return [self initWithValues:NULL count:0]; 816 self = [super init];
817 // No work needed;
818 return self;
811 } 819 }
812 820
813 - (instancetype)initWithValueArray:(GPBInt64Array *)array { 821 - (instancetype)initWithValueArray:(GPBInt64Array *)array {
814 return [self initWithValues:array->_values count:array->_count]; 822 return [self initWithValues:array->_values count:array->_count];
815 } 823 }
816 824
817 - (instancetype)initWithValues:(const int64_t [])values count:(NSUInteger)count { 825 - (instancetype)initWithValues:(const int64_t [])values count:(NSUInteger)count {
818 self = [super init]; 826 self = [self init];
819 if (self) { 827 if (self) {
820 if (count && values) { 828 if (count && values) {
821 _values = malloc(count * sizeof(int64_t)); 829 _values = reallocf(_values, count * sizeof(int64_t));
822 if (values != NULL) { 830 if (_values != NULL) {
823 _capacity = count; 831 _capacity = count;
824 memcpy(_values, values, count * sizeof(int64_t)); 832 memcpy(_values, values, count * sizeof(int64_t));
825 _count = count; 833 _count = count;
826 } else { 834 } else {
827 [self release]; 835 [self release];
828 [NSException raise:NSMallocException 836 [NSException raise:NSMallocException
829 format:@"Failed to allocate %lu bytes", 837 format:@"Failed to allocate %lu bytes",
830 (unsigned long)(count * sizeof(int64_t))]; 838 (unsigned long)(count * sizeof(int64_t))];
831 } 839 }
832 } 840 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 @implementation GPBUInt64Array { 1035 @implementation GPBUInt64Array {
1028 @package 1036 @package
1029 uint64_t *_values; 1037 uint64_t *_values;
1030 NSUInteger _count; 1038 NSUInteger _count;
1031 NSUInteger _capacity; 1039 NSUInteger _capacity;
1032 } 1040 }
1033 1041
1034 @synthesize count = _count; 1042 @synthesize count = _count;
1035 1043
1036 + (instancetype)array { 1044 + (instancetype)array {
1037 return [[[self alloc] initWithValues:NULL count:0] autorelease]; 1045 return [[[self alloc] init] autorelease];
1038 } 1046 }
1039 1047
1040 + (instancetype)arrayWithValue:(uint64_t)value { 1048 + (instancetype)arrayWithValue:(uint64_t)value {
1041 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get 1049 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get
1042 // the type correct. 1050 // the type correct.
1043 return [[(GPBUInt64Array*)[self alloc] initWithValues:&value count:1] autorele ase]; 1051 return [[(GPBUInt64Array*)[self alloc] initWithValues:&value count:1] autorele ase];
1044 } 1052 }
1045 1053
1046 + (instancetype)arrayWithValueArray:(GPBUInt64Array *)array { 1054 + (instancetype)arrayWithValueArray:(GPBUInt64Array *)array {
1047 return [[(GPBUInt64Array*)[self alloc] initWithValueArray:array] autorelease]; 1055 return [[(GPBUInt64Array*)[self alloc] initWithValueArray:array] autorelease];
1048 } 1056 }
1049 1057
1050 + (instancetype)arrayWithCapacity:(NSUInteger)count { 1058 + (instancetype)arrayWithCapacity:(NSUInteger)count {
1051 return [[[self alloc] initWithCapacity:count] autorelease]; 1059 return [[[self alloc] initWithCapacity:count] autorelease];
1052 } 1060 }
1053 1061
1054 - (instancetype)init { 1062 - (instancetype)init {
1055 return [self initWithValues:NULL count:0]; 1063 self = [super init];
1064 // No work needed;
1065 return self;
1056 } 1066 }
1057 1067
1058 - (instancetype)initWithValueArray:(GPBUInt64Array *)array { 1068 - (instancetype)initWithValueArray:(GPBUInt64Array *)array {
1059 return [self initWithValues:array->_values count:array->_count]; 1069 return [self initWithValues:array->_values count:array->_count];
1060 } 1070 }
1061 1071
1062 - (instancetype)initWithValues:(const uint64_t [])values count:(NSUInteger)count { 1072 - (instancetype)initWithValues:(const uint64_t [])values count:(NSUInteger)count {
1063 self = [super init]; 1073 self = [self init];
1064 if (self) { 1074 if (self) {
1065 if (count && values) { 1075 if (count && values) {
1066 _values = malloc(count * sizeof(uint64_t)); 1076 _values = reallocf(_values, count * sizeof(uint64_t));
1067 if (values != NULL) { 1077 if (_values != NULL) {
1068 _capacity = count; 1078 _capacity = count;
1069 memcpy(_values, values, count * sizeof(uint64_t)); 1079 memcpy(_values, values, count * sizeof(uint64_t));
1070 _count = count; 1080 _count = count;
1071 } else { 1081 } else {
1072 [self release]; 1082 [self release];
1073 [NSException raise:NSMallocException 1083 [NSException raise:NSMallocException
1074 format:@"Failed to allocate %lu bytes", 1084 format:@"Failed to allocate %lu bytes",
1075 (unsigned long)(count * sizeof(uint64_t))]; 1085 (unsigned long)(count * sizeof(uint64_t))];
1076 } 1086 }
1077 } 1087 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 @implementation GPBFloatArray { 1282 @implementation GPBFloatArray {
1273 @package 1283 @package
1274 float *_values; 1284 float *_values;
1275 NSUInteger _count; 1285 NSUInteger _count;
1276 NSUInteger _capacity; 1286 NSUInteger _capacity;
1277 } 1287 }
1278 1288
1279 @synthesize count = _count; 1289 @synthesize count = _count;
1280 1290
1281 + (instancetype)array { 1291 + (instancetype)array {
1282 return [[[self alloc] initWithValues:NULL count:0] autorelease]; 1292 return [[[self alloc] init] autorelease];
1283 } 1293 }
1284 1294
1285 + (instancetype)arrayWithValue:(float)value { 1295 + (instancetype)arrayWithValue:(float)value {
1286 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get 1296 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get
1287 // the type correct. 1297 // the type correct.
1288 return [[(GPBFloatArray*)[self alloc] initWithValues:&value count:1] autorelea se]; 1298 return [[(GPBFloatArray*)[self alloc] initWithValues:&value count:1] autorelea se];
1289 } 1299 }
1290 1300
1291 + (instancetype)arrayWithValueArray:(GPBFloatArray *)array { 1301 + (instancetype)arrayWithValueArray:(GPBFloatArray *)array {
1292 return [[(GPBFloatArray*)[self alloc] initWithValueArray:array] autorelease]; 1302 return [[(GPBFloatArray*)[self alloc] initWithValueArray:array] autorelease];
1293 } 1303 }
1294 1304
1295 + (instancetype)arrayWithCapacity:(NSUInteger)count { 1305 + (instancetype)arrayWithCapacity:(NSUInteger)count {
1296 return [[[self alloc] initWithCapacity:count] autorelease]; 1306 return [[[self alloc] initWithCapacity:count] autorelease];
1297 } 1307 }
1298 1308
1299 - (instancetype)init { 1309 - (instancetype)init {
1300 return [self initWithValues:NULL count:0]; 1310 self = [super init];
1311 // No work needed;
1312 return self;
1301 } 1313 }
1302 1314
1303 - (instancetype)initWithValueArray:(GPBFloatArray *)array { 1315 - (instancetype)initWithValueArray:(GPBFloatArray *)array {
1304 return [self initWithValues:array->_values count:array->_count]; 1316 return [self initWithValues:array->_values count:array->_count];
1305 } 1317 }
1306 1318
1307 - (instancetype)initWithValues:(const float [])values count:(NSUInteger)count { 1319 - (instancetype)initWithValues:(const float [])values count:(NSUInteger)count {
1308 self = [super init]; 1320 self = [self init];
1309 if (self) { 1321 if (self) {
1310 if (count && values) { 1322 if (count && values) {
1311 _values = malloc(count * sizeof(float)); 1323 _values = reallocf(_values, count * sizeof(float));
1312 if (values != NULL) { 1324 if (_values != NULL) {
1313 _capacity = count; 1325 _capacity = count;
1314 memcpy(_values, values, count * sizeof(float)); 1326 memcpy(_values, values, count * sizeof(float));
1315 _count = count; 1327 _count = count;
1316 } else { 1328 } else {
1317 [self release]; 1329 [self release];
1318 [NSException raise:NSMallocException 1330 [NSException raise:NSMallocException
1319 format:@"Failed to allocate %lu bytes", 1331 format:@"Failed to allocate %lu bytes",
1320 (unsigned long)(count * sizeof(float))]; 1332 (unsigned long)(count * sizeof(float))];
1321 } 1333 }
1322 } 1334 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 @implementation GPBDoubleArray { 1529 @implementation GPBDoubleArray {
1518 @package 1530 @package
1519 double *_values; 1531 double *_values;
1520 NSUInteger _count; 1532 NSUInteger _count;
1521 NSUInteger _capacity; 1533 NSUInteger _capacity;
1522 } 1534 }
1523 1535
1524 @synthesize count = _count; 1536 @synthesize count = _count;
1525 1537
1526 + (instancetype)array { 1538 + (instancetype)array {
1527 return [[[self alloc] initWithValues:NULL count:0] autorelease]; 1539 return [[[self alloc] init] autorelease];
1528 } 1540 }
1529 1541
1530 + (instancetype)arrayWithValue:(double)value { 1542 + (instancetype)arrayWithValue:(double)value {
1531 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get 1543 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get
1532 // the type correct. 1544 // the type correct.
1533 return [[(GPBDoubleArray*)[self alloc] initWithValues:&value count:1] autorele ase]; 1545 return [[(GPBDoubleArray*)[self alloc] initWithValues:&value count:1] autorele ase];
1534 } 1546 }
1535 1547
1536 + (instancetype)arrayWithValueArray:(GPBDoubleArray *)array { 1548 + (instancetype)arrayWithValueArray:(GPBDoubleArray *)array {
1537 return [[(GPBDoubleArray*)[self alloc] initWithValueArray:array] autorelease]; 1549 return [[(GPBDoubleArray*)[self alloc] initWithValueArray:array] autorelease];
1538 } 1550 }
1539 1551
1540 + (instancetype)arrayWithCapacity:(NSUInteger)count { 1552 + (instancetype)arrayWithCapacity:(NSUInteger)count {
1541 return [[[self alloc] initWithCapacity:count] autorelease]; 1553 return [[[self alloc] initWithCapacity:count] autorelease];
1542 } 1554 }
1543 1555
1544 - (instancetype)init { 1556 - (instancetype)init {
1545 return [self initWithValues:NULL count:0]; 1557 self = [super init];
1558 // No work needed;
1559 return self;
1546 } 1560 }
1547 1561
1548 - (instancetype)initWithValueArray:(GPBDoubleArray *)array { 1562 - (instancetype)initWithValueArray:(GPBDoubleArray *)array {
1549 return [self initWithValues:array->_values count:array->_count]; 1563 return [self initWithValues:array->_values count:array->_count];
1550 } 1564 }
1551 1565
1552 - (instancetype)initWithValues:(const double [])values count:(NSUInteger)count { 1566 - (instancetype)initWithValues:(const double [])values count:(NSUInteger)count {
1553 self = [super init]; 1567 self = [self init];
1554 if (self) { 1568 if (self) {
1555 if (count && values) { 1569 if (count && values) {
1556 _values = malloc(count * sizeof(double)); 1570 _values = reallocf(_values, count * sizeof(double));
1557 if (values != NULL) { 1571 if (_values != NULL) {
1558 _capacity = count; 1572 _capacity = count;
1559 memcpy(_values, values, count * sizeof(double)); 1573 memcpy(_values, values, count * sizeof(double));
1560 _count = count; 1574 _count = count;
1561 } else { 1575 } else {
1562 [self release]; 1576 [self release];
1563 [NSException raise:NSMallocException 1577 [NSException raise:NSMallocException
1564 format:@"Failed to allocate %lu bytes", 1578 format:@"Failed to allocate %lu bytes",
1565 (unsigned long)(count * sizeof(double))]; 1579 (unsigned long)(count * sizeof(double))];
1566 } 1580 }
1567 } 1581 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 @implementation GPBBoolArray { 1776 @implementation GPBBoolArray {
1763 @package 1777 @package
1764 BOOL *_values; 1778 BOOL *_values;
1765 NSUInteger _count; 1779 NSUInteger _count;
1766 NSUInteger _capacity; 1780 NSUInteger _capacity;
1767 } 1781 }
1768 1782
1769 @synthesize count = _count; 1783 @synthesize count = _count;
1770 1784
1771 + (instancetype)array { 1785 + (instancetype)array {
1772 return [[[self alloc] initWithValues:NULL count:0] autorelease]; 1786 return [[[self alloc] init] autorelease];
1773 } 1787 }
1774 1788
1775 + (instancetype)arrayWithValue:(BOOL)value { 1789 + (instancetype)arrayWithValue:(BOOL)value {
1776 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get 1790 // Cast is needed so the compiler knows what class we are invoking initWithVal ues: on to get
1777 // the type correct. 1791 // the type correct.
1778 return [[(GPBBoolArray*)[self alloc] initWithValues:&value count:1] autoreleas e]; 1792 return [[(GPBBoolArray*)[self alloc] initWithValues:&value count:1] autoreleas e];
1779 } 1793 }
1780 1794
1781 + (instancetype)arrayWithValueArray:(GPBBoolArray *)array { 1795 + (instancetype)arrayWithValueArray:(GPBBoolArray *)array {
1782 return [[(GPBBoolArray*)[self alloc] initWithValueArray:array] autorelease]; 1796 return [[(GPBBoolArray*)[self alloc] initWithValueArray:array] autorelease];
1783 } 1797 }
1784 1798
1785 + (instancetype)arrayWithCapacity:(NSUInteger)count { 1799 + (instancetype)arrayWithCapacity:(NSUInteger)count {
1786 return [[[self alloc] initWithCapacity:count] autorelease]; 1800 return [[[self alloc] initWithCapacity:count] autorelease];
1787 } 1801 }
1788 1802
1789 - (instancetype)init { 1803 - (instancetype)init {
1790 return [self initWithValues:NULL count:0]; 1804 self = [super init];
1805 // No work needed;
1806 return self;
1791 } 1807 }
1792 1808
1793 - (instancetype)initWithValueArray:(GPBBoolArray *)array { 1809 - (instancetype)initWithValueArray:(GPBBoolArray *)array {
1794 return [self initWithValues:array->_values count:array->_count]; 1810 return [self initWithValues:array->_values count:array->_count];
1795 } 1811 }
1796 1812
1797 - (instancetype)initWithValues:(const BOOL [])values count:(NSUInteger)count { 1813 - (instancetype)initWithValues:(const BOOL [])values count:(NSUInteger)count {
1798 self = [super init]; 1814 self = [self init];
1799 if (self) { 1815 if (self) {
1800 if (count && values) { 1816 if (count && values) {
1801 _values = malloc(count * sizeof(BOOL)); 1817 _values = reallocf(_values, count * sizeof(BOOL));
1802 if (values != NULL) { 1818 if (_values != NULL) {
1803 _capacity = count; 1819 _capacity = count;
1804 memcpy(_values, values, count * sizeof(BOOL)); 1820 memcpy(_values, values, count * sizeof(BOOL));
1805 _count = count; 1821 _count = count;
1806 } else { 1822 } else {
1807 [self release]; 1823 [self release];
1808 [NSException raise:NSMallocException 1824 [NSException raise:NSMallocException
1809 format:@"Failed to allocate %lu bytes", 1825 format:@"Failed to allocate %lu bytes",
1810 (unsigned long)(count * sizeof(BOOL))]; 1826 (unsigned long)(count * sizeof(BOOL))];
1811 } 1827 }
1812 } 1828 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 GPBEnumValidationFunc _validationFunc; 2024 GPBEnumValidationFunc _validationFunc;
2009 int32_t *_values; 2025 int32_t *_values;
2010 NSUInteger _count; 2026 NSUInteger _count;
2011 NSUInteger _capacity; 2027 NSUInteger _capacity;
2012 } 2028 }
2013 2029
2014 @synthesize count = _count; 2030 @synthesize count = _count;
2015 @synthesize validationFunc = _validationFunc; 2031 @synthesize validationFunc = _validationFunc;
2016 2032
2017 + (instancetype)array { 2033 + (instancetype)array {
2018 return [[[self alloc] initWithValidationFunction:NULL 2034 return [[[self alloc] initWithValidationFunction:NULL] autorelease];
2019 rawValues:NULL
2020 count:0] autorelease];
2021 } 2035 }
2022 2036
2023 + (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func { 2037 + (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func {
2024 return [[[self alloc] initWithValidationFunction:func 2038 return [[[self alloc] initWithValidationFunction:func] autorelease];
2025 rawValues:NULL
2026 count:0] autorelease];
2027 } 2039 }
2028 2040
2029 + (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func 2041 + (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
2030 rawValue:(int32_t)value { 2042 rawValue:(int32_t)value {
2031 return [[[self alloc] initWithValidationFunction:func 2043 return [[[self alloc] initWithValidationFunction:func
2032 rawValues:&value 2044 rawValues:&value
2033 count:1] autorelease]; 2045 count:1] autorelease];
2034 } 2046 }
2035 2047
2036 + (instancetype)arrayWithValueArray:(GPBEnumArray *)array { 2048 + (instancetype)arrayWithValueArray:(GPBEnumArray *)array {
2037 return [[(GPBEnumArray*)[self alloc] initWithValueArray:array] autorelease]; 2049 return [[(GPBEnumArray*)[self alloc] initWithValueArray:array] autorelease];
2038 } 2050 }
2039 2051
2040 + (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func 2052 + (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
2041 capacity:(NSUInteger)count { 2053 capacity:(NSUInteger)count {
2042 return [[[self alloc] initWithValidationFunction:func capacity:count] autorele ase]; 2054 return [[[self alloc] initWithValidationFunction:func capacity:count] autorele ase];
2043 } 2055 }
2044 2056
2045 - (instancetype)init { 2057 - (instancetype)init {
2046 return [self initWithValidationFunction:NULL rawValues:NULL count:0]; 2058 return [self initWithValidationFunction:NULL];
2047 } 2059 }
2048 2060
2049 - (instancetype)initWithValueArray:(GPBEnumArray *)array { 2061 - (instancetype)initWithValueArray:(GPBEnumArray *)array {
2050 return [self initWithValidationFunction:array->_validationFunc 2062 return [self initWithValidationFunction:array->_validationFunc
2051 rawValues:array->_values 2063 rawValues:array->_values
2052 count:array->_count]; 2064 count:array->_count];
2053 } 2065 }
2054 2066
2055 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 2067 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
2056 return [self initWithValidationFunction:func rawValues:NULL count:0]; 2068 self = [super init];
2069 if (self) {
2070 _validationFunc = (func != NULL ? func : ArrayDefault_IsValidValue);
2071 }
2072 return self;
2057 } 2073 }
2058 2074
2059 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 2075 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2060 rawValues:(const int32_t [])values 2076 rawValues:(const int32_t [])values
2061 count:(NSUInteger)count { 2077 count:(NSUInteger)count {
2062 self = [super init]; 2078 self = [self initWithValidationFunction:func];
2063 if (self) { 2079 if (self) {
2064 _validationFunc = (func != NULL ? func : ArrayDefault_IsValidValue);
2065 if (count && values) { 2080 if (count && values) {
2066 _values = malloc(count * sizeof(int32_t)); 2081 _values = reallocf(_values, count * sizeof(int32_t));
2067 if (values != NULL) { 2082 if (_values != NULL) {
2068 _capacity = count; 2083 _capacity = count;
2069 memcpy(_values, values, count * sizeof(int32_t)); 2084 memcpy(_values, values, count * sizeof(int32_t));
2070 _count = count; 2085 _count = count;
2071 } else { 2086 } else {
2072 [self release]; 2087 [self release];
2073 [NSException raise:NSMallocException 2088 [NSException raise:NSMallocException
2074 format:@"Failed to allocate %lu bytes", 2089 format:@"Failed to allocate %lu bytes",
2075 (unsigned long)(count * sizeof(int32_t))]; 2090 (unsigned long)(count * sizeof(int32_t))];
2076 } 2091 }
2077 } 2092 }
2078 } 2093 }
2079 return self; 2094 return self;
2080 } 2095 }
2081 2096
2082 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 2097 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2083 capacity:(NSUInteger)count { 2098 capacity:(NSUInteger)count {
2084 self = [self initWithValidationFunction:func rawValues:NULL count:0]; 2099 self = [self initWithValidationFunction:func];
2085 if (self && count) { 2100 if (self && count) {
2086 [self internalResizeToCapacity:count]; 2101 [self internalResizeToCapacity:count];
2087 } 2102 }
2088 return self; 2103 return self;
2089 } 2104 }
2090 2105
2091 - (instancetype)copyWithZone:(NSZone *)zone { 2106 - (instancetype)copyWithZone:(NSZone *)zone {
2092 return [[GPBEnumArray allocWithZone:zone] 2107 return [[GPBEnumArray allocWithZone:zone]
2093 initWithValidationFunction:_validationFunc 2108 initWithValidationFunction:_validationFunc
2094 rawValues:_values 2109 rawValues:_values
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
2510 - (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop) )block { 2525 - (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop) )block {
2511 [_array enumerateObjectsUsingBlock:block]; 2526 [_array enumerateObjectsUsingBlock:block];
2512 } 2527 }
2513 2528
2514 - (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts 2529 - (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts
2515 usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop ))block { 2530 usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop ))block {
2516 [_array enumerateObjectsWithOptions:opts usingBlock:block]; 2531 [_array enumerateObjectsWithOptions:opts usingBlock:block];
2517 } 2532 }
2518 2533
2519 @end 2534 @end
OLDNEW
« no previous file with comments | « third_party/protobuf/objectivec/GPBArray.h ('k') | third_party/protobuf/objectivec/GPBBootstrap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698