diff options
Diffstat (limited to 'objectivec/GPBDictionary.m')
-rw-r--r-- | objectivec/GPBDictionary.m | 4521 |
1 files changed, 1507 insertions, 3014 deletions
diff --git a/objectivec/GPBDictionary.m b/objectivec/GPBDictionary.m index 1c67c680..cedf5e54 100644 --- a/objectivec/GPBDictionary.m +++ b/objectivec/GPBDictionary.m @@ -329,13 +329,15 @@ static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_ size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) { GPBDataType mapValueType = GPBGetFieldDataType(field); - __block size_t result = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSString *key; + NSEnumerator *keys = [dict keyEnumerator]; + while ((key = [keys nextObject])) { + id obj = dict[key]; size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key); msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * dict.count; return result; @@ -347,8 +349,10 @@ void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); GPBDataType mapValueType = GPBGetFieldDataType(field); uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { - #pragma unused(stop) + NSString *key; + NSEnumerator *keys = [dict keyEnumerator]; + while ((key = [keys nextObject])) { + id obj = dict[key]; // Write the tag. [outputStream writeInt32NoTag:tag]; // Write the size of the message. @@ -359,14 +363,16 @@ void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream [outputStream writeInt32NoTag:(int32_t)msgSize]; [outputStream writeString:kMapKeyFieldNumber value:key]; WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType); - }]; + } } BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) { NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type"); #pragma unused(field) // For when asserts are off in release. - for (GPBMessage *msg in [dict objectEnumerator]) { + GPBMessage *msg; + NSEnumerator *objects = [dict objectEnumerator]; + while ((msg = [objects nextObject])) { if (!msg.initialized) { return NO; } @@ -406,7 +412,7 @@ static void ReadValue(GPBCodedInputStream *stream, valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_); break; case GPBDataTypeInt64: - valueToFill->valueInt64 = GPBCodedInputStreamReadInt32(&stream->state_); + valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_); break; case GPBDataTypeSInt32: valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_); @@ -590,39 +596,6 @@ void GPBDictionaryReadEntry(id mapDictionary, //% NSMutableDictionary *_dictionary; //%} //% -//%+ (instancetype)dictionary { -//% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR -//% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key { -//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count: -//% // on to get the type correct. -//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:&##VNAME_VAR -//% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:&key -//% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:1] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s -//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys -//% ##VNAME$S## count:(NSUInteger)count { -//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count: -//% // on to get the type correct. -//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:##VNAME_VAR##s -//% KEY_NAME$S VALUE_NAME$S forKeys:keys -//% KEY_NAME$S VALUE_NAME$S count:count] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary { -//% // Cast is needed so the compiler knows what class we are invoking initWithDictionary: -//% // on to get the type correct. -//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { -//% return [[[self alloc] initWithCapacity:numItems] autorelease]; -//%} -//% //%- (instancetype)init { //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; //%} @@ -679,54 +652,6 @@ void GPBDictionaryReadEntry(id mapDictionary, //% //%@synthesize validationFunc = _validationFunc; //% -//%+ (instancetype)dictionary { -//% return [[[self alloc] initWithValidationFunction:NULL -//% rawValues:NULL -//% forKeys:NULL -//% count:0] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { -//% return [[[self alloc] initWithValidationFunction:func -//% rawValues:NULL -//% forKeys:NULL -//% count:0] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func -//% rawValue:(VALUE_TYPE)rawValue -//% forKey:(KEY_TYPE##KisP$S##KisP)key { -//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: -//% // on to get the type correct. -//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValidationFunction:func -//% KEY_NAME$S VALUE_NAME$S rawValues:&rawValue -//% KEY_NAME$S VALUE_NAME$S forKeys:&key -//% KEY_NAME$S VALUE_NAME$S count:1] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func -//% rawValues:(const VALUE_TYPE [])rawValues -//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys -//% count:(NSUInteger)count { -//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: -//% // on to get the type correct. -//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValidationFunction:func -//% KEY_NAME$S VALUE_NAME$S rawValues:rawValues -//% KEY_NAME$S VALUE_NAME$S forKeys:keys -//% KEY_NAME$S VALUE_NAME$S count:count] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary { -//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: -//% // on to get the type correct. -//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func -//% capacity:(NSUInteger)numItems { -//% return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease]; -//%} -//% //%- (instancetype)init { //% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; //%} @@ -796,15 +721,20 @@ void GPBDictionaryReadEntry(id mapDictionary, //%- (void)enumerateKeysAndEnumsUsingBlock: //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { //% GPBEnumValidationFunc func = _validationFunc; -//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey, -//% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue, -//% BOOL *stop) { +//% BOOL stop = NO; +//% NSEnumerator *keys = [_dictionary keyEnumerator]; +//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; +//% while ((aKey = [keys nextObject])) { +//% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey]; //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue); //% if (!func(unwrapped)) { //% unwrapped = kGPBUnrecognizedEnumeratorValue; //% } -//% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop); -//% }]; +//% block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop); +//% if (stop) { +//% break; +//% } +//% } //%} //% //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw) @@ -863,30 +793,37 @@ void GPBDictionaryReadEntry(id mapDictionary, //% //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock: //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block { -//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey, -//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u, -//% BOOL *stop) { -//% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), stop); -//% }]; +//% BOOL stop = NO; +//% NSDictionary *internal = _dictionary; +//% NSEnumerator *keys = [internal keyEnumerator]; +//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; +//% while ((aKey = [keys nextObject])) { +//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey]; +//% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop); +//% if (stop) { +//% break; +//% } +//% } //%} //% //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { -//% NSUInteger count = _dictionary.count; +//% NSDictionary *internal = _dictionary; +//% NSUInteger count = internal.count; //% if (count == 0) { //% return 0; //% } //% //% GPBDataType valueDataType = GPBGetFieldDataType(field); //% GPBDataType keyDataType = field.mapKeyDataType; -//% __block size_t result = 0; -//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey, -//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u##, -//% BOOL *stop) { -//% #pragma unused(stop) +//% size_t result = 0; +//% NSEnumerator *keys = [internal keyEnumerator]; +//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; +//% while ((aKey = [keys nextObject])) { +//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey]; //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType); //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType); //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; -//% }]; +//% } //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); //% result += tagSize * count; //% return result; @@ -897,20 +834,22 @@ void GPBDictionaryReadEntry(id mapDictionary, //% GPBDataType valueDataType = GPBGetFieldDataType(field); //% GPBDataType keyDataType = field.mapKeyDataType; //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); -//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey, -//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u, -//% BOOL *stop) { -//% #pragma unused(stop) -//% // Write the tag. +//% NSDictionary *internal = _dictionary; +//% NSEnumerator *keys = [internal keyEnumerator]; +//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; +//% while ((aKey = [keys nextObject])) { +//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey]; //% [outputStream writeInt32NoTag:tag]; //% // Write the size of the message. -//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType); -//% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType); +//% KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey); +//% VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u); +//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); +//% msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); //% [outputStream writeInt32NoTag:(int32_t)msgSize]; //% // Write the fields. -//% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType); -//% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType); -//% }]; +//% WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); +//% WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); +//% } //%} //% //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value @@ -968,39 +907,6 @@ void GPBDictionaryReadEntry(id mapDictionary, //% VALUE_TYPE _values[2]; //%BOOL_DICT_HAS_STORAGE_##HELPER()} //% -//%+ (instancetype)dictionary { -//% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)VNAME_VAR -//% ##VNAME$S## forKey:(BOOL)key { -//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count: -//% // on to get the type correct. -//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:&##VNAME_VAR -//% VALUE_NAME$S ##VNAME$S## forKeys:&key -//% VALUE_NAME$S ##VNAME$S## count:1] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s -//% ##VNAME$S## forKeys:(const BOOL [])keys -//% ##VNAME$S## count:(NSUInteger)count { -//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count: -//% // on to get the type correct. -//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:##VNAME_VAR##s -//% VALUE_NAME$S ##VNAME$S## forKeys:keys -//% VALUE_NAME$S ##VNAME$S## count:count] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary { -//% // Cast is needed so the compiler knows what class we are invoking initWithDictionary: -//% // on to get the type correct. -//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -//%} -//% -//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { -//% return [[[self alloc] initWithCapacity:numItems] autorelease]; -//%} -//% //%- (instancetype)init { //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; //%} @@ -1366,14 +1272,15 @@ void GPBDictionaryReadEntry(id mapDictionary, //%- (instancetype)deepCopyWithZone:(NSZone *)zone { //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; -//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, -//% GPBMessage *msg, -//% BOOL *stop) { -//% #pragma unused(stop) +//% NSEnumerator *keys = [_dictionary keyEnumerator]; +//% id aKey; +//% NSMutableDictionary *internalDict = newDict->_dictionary; +//% while ((aKey = [keys nextObject])) { +//% GPBMessage *msg = _dictionary[aKey]; //% GPBMessage *copiedMsg = [msg copyWithZone:zone]; -//% [newDict->_dictionary setObject:copiedMsg forKey:aKey]; +//% [internalDict setObject:copiedMsg forKey:aKey]; //% [copiedMsg release]; -//% }]; +//% } //% return newDict; //%} //% @@ -1528,39 +1435,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32:(uint32_t)value - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -1632,30 +1506,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt32sUsingBlock: (void (^)(uint32_t key, uint32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue unsignedIntValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue unsignedIntValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -1666,20 +1547,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + uint32_t unwrappedValue = [aValue unsignedIntValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -1735,39 +1618,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt32:(int32_t)value - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt32s:(const int32_t [])values - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -1839,30 +1689,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt32sUsingBlock: (void (^)(uint32_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -1873,20 +1730,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -1942,39 +1801,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64:(uint64_t)value - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -2046,30 +1872,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt64sUsingBlock: (void (^)(uint32_t key, uint64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue unsignedLongLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -2080,20 +1913,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + uint64_t unwrappedValue = [aValue unsignedLongLongValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -2149,39 +1984,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt64:(int64_t)value - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt64s:(const int64_t [])values - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -2253,30 +2055,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt64sUsingBlock: (void (^)(uint32_t key, int64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue longLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue longLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -2287,20 +2096,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + int64_t unwrappedValue = [aValue longLongValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -2356,39 +2167,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithBool:(BOOL)value - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithBools:(const BOOL [])values - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -2460,30 +2238,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndBoolsUsingBlock: (void (^)(uint32_t key, BOOL value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue boolValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue boolValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -2494,20 +2279,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + BOOL unwrappedValue = [aValue boolValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -2563,39 +2350,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithFloat:(float)value - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithFloats:(const float [])values - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -2667,30 +2421,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndFloatsUsingBlock: (void (^)(uint32_t key, float value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue floatValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue floatValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -2701,20 +2462,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + float unwrappedValue = [aValue floatValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -2770,39 +2533,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithDouble:(double)value - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithDoubles:(const double [])values - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -2874,30 +2604,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndDoublesUsingBlock: (void (^)(uint32_t key, double value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue doubleValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue doubleValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -2908,20 +2645,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + double unwrappedValue = [aValue doubleValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -2980,54 +2719,6 @@ void GPBDictionaryReadEntry(id mapDictionary, @synthesize validationFunc = _validationFunc; -+ (instancetype)dictionary { - return [[[self alloc] initWithValidationFunction:NULL - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { - return [[[self alloc] initWithValidationFunction:func - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValue:(int32_t)rawValue - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:&rawValue - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t [])rawValues - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:rawValues - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(NSUInteger)numItems { - return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; } @@ -3109,30 +2800,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndRawValuesUsingBlock: (void (^)(uint32_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedIntValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedIntValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -3143,20 +2841,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (NSData *)serializedDataForUnknownValue:(int32_t)value @@ -3206,15 +2906,20 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndEnumsUsingBlock: (void (^)(uint32_t key, int32_t value, BOOL *stop))block { GPBEnumValidationFunc func = _validationFunc; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { + BOOL stop = NO; + NSEnumerator *keys = [_dictionary keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = _dictionary[aKey]; int32_t unwrapped = [aValue intValue]; if (!func(unwrapped)) { unwrapped = kGPBUnrecognizedEnumeratorValue; } - block([aKey unsignedIntValue], unwrapped, stop); - }]; + block([aKey unsignedIntValue], unwrapped, &stop); + if (stop) { + break; + } + } } - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary { @@ -3263,39 +2968,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithObject:(id)object - forKey:(uint32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithObjects:&object - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithObjects:(const id [])objects - forKeys:(const uint32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithObjects:objects - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -3371,11 +3043,17 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndObjectsUsingBlock: (void (^)(uint32_t key, id object, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - block([aKey unsignedIntValue], aObject, stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; + block([aKey unsignedIntValue], aObject, &stop); + if (stop) { + break; + } + } } - (BOOL)isInitialized { @@ -3390,34 +3068,36 @@ void GPBDictionaryReadEntry(id mapDictionary, - (instancetype)deepCopyWithZone:(NSZone *)zone { GPBUInt32ObjectDictionary *newDict = [[GPBUInt32ObjectDictionary alloc] init]; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, - GPBMessage *msg, - BOOL *stop) { - #pragma unused(stop) + NSEnumerator *keys = [_dictionary keyEnumerator]; + id aKey; + NSMutableDictionary *internalDict = newDict->_dictionary; + while ((aKey = [keys nextObject])) { + GPBMessage *msg = _dictionary[aKey]; GPBMessage *copiedMsg = [msg copyWithZone:zone]; - [newDict->_dictionary setObject:copiedMsg forKey:aKey]; + [internalDict setObject:copiedMsg forKey:aKey]; [copiedMsg release]; - }]; + } return newDict; } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -3428,20 +3108,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); + uint32_t unwrappedKey = [aKey unsignedIntValue]; + id unwrappedValue = aObject; + size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); - WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -3501,39 +3183,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32:(uint32_t)value - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -3605,30 +3254,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt32sUsingBlock: (void (^)(int32_t key, uint32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue unsignedIntValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue unsignedIntValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -3639,20 +3295,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + uint32_t unwrappedValue = [aValue unsignedIntValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -3708,39 +3366,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt32:(int32_t)value - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt32s:(const int32_t [])values - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -3812,30 +3437,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt32sUsingBlock: (void (^)(int32_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -3846,20 +3478,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -3915,39 +3549,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64:(uint64_t)value - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -4019,30 +3620,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt64sUsingBlock: (void (^)(int32_t key, uint64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue unsignedLongLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue unsignedLongLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -4053,20 +3661,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + uint64_t unwrappedValue = [aValue unsignedLongLongValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -4122,39 +3732,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt64:(int64_t)value - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt64s:(const int64_t [])values - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -4226,30 +3803,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt64sUsingBlock: (void (^)(int32_t key, int64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue longLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue longLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -4260,20 +3844,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + int64_t unwrappedValue = [aValue longLongValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -4329,39 +3915,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithBool:(BOOL)value - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithBools:(const BOOL [])values - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -4433,30 +3986,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndBoolsUsingBlock: (void (^)(int32_t key, BOOL value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue boolValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue boolValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -4467,20 +4027,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + BOOL unwrappedValue = [aValue boolValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -4536,39 +4098,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithFloat:(float)value - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithFloats:(const float [])values - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -4640,30 +4169,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndFloatsUsingBlock: (void (^)(int32_t key, float value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue floatValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue floatValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -4674,20 +4210,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + float unwrappedValue = [aValue floatValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -4743,39 +4281,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithDouble:(double)value - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithDoubles:(const double [])values - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -4847,30 +4352,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndDoublesUsingBlock: (void (^)(int32_t key, double value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue doubleValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue doubleValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -4881,20 +4393,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + double unwrappedValue = [aValue doubleValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -4953,54 +4467,6 @@ void GPBDictionaryReadEntry(id mapDictionary, @synthesize validationFunc = _validationFunc; -+ (instancetype)dictionary { - return [[[self alloc] initWithValidationFunction:NULL - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { - return [[[self alloc] initWithValidationFunction:func - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValue:(int32_t)rawValue - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:&rawValue - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t [])rawValues - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:rawValues - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(NSUInteger)numItems { - return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; } @@ -5082,30 +4548,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndRawValuesUsingBlock: (void (^)(int32_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey intValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey intValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -5116,20 +4589,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (NSData *)serializedDataForUnknownValue:(int32_t)value @@ -5179,15 +4654,20 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndEnumsUsingBlock: (void (^)(int32_t key, int32_t value, BOOL *stop))block { GPBEnumValidationFunc func = _validationFunc; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { + BOOL stop = NO; + NSEnumerator *keys = [_dictionary keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = _dictionary[aKey]; int32_t unwrapped = [aValue intValue]; if (!func(unwrapped)) { unwrapped = kGPBUnrecognizedEnumeratorValue; } - block([aKey intValue], unwrapped, stop); - }]; + block([aKey intValue], unwrapped, &stop); + if (stop) { + break; + } + } } - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary { @@ -5236,39 +4716,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithObject:(id)object - forKey:(int32_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBInt32ObjectDictionary*)[self alloc] initWithObjects:&object - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithObjects:(const id [])objects - forKeys:(const int32_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBInt32ObjectDictionary*)[self alloc] initWithObjects:objects - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -5344,11 +4791,17 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndObjectsUsingBlock: (void (^)(int32_t key, id object, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - block([aKey intValue], aObject, stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; + block([aKey intValue], aObject, &stop); + if (stop) { + break; + } + } } - (BOOL)isInitialized { @@ -5363,34 +4816,36 @@ void GPBDictionaryReadEntry(id mapDictionary, - (instancetype)deepCopyWithZone:(NSZone *)zone { GPBInt32ObjectDictionary *newDict = [[GPBInt32ObjectDictionary alloc] init]; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, - GPBMessage *msg, - BOOL *stop) { - #pragma unused(stop) + NSEnumerator *keys = [_dictionary keyEnumerator]; + id aKey; + NSMutableDictionary *internalDict = newDict->_dictionary; + while ((aKey = [keys nextObject])) { + GPBMessage *msg = _dictionary[aKey]; GPBMessage *copiedMsg = [msg copyWithZone:zone]; - [newDict->_dictionary setObject:copiedMsg forKey:aKey]; + [internalDict setObject:copiedMsg forKey:aKey]; [copiedMsg release]; - }]; + } return newDict; } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -5401,20 +4856,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); + int32_t unwrappedKey = [aKey intValue]; + id unwrappedValue = aObject; + size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType); - WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -5474,39 +4931,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32:(uint32_t)value - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -5578,30 +5002,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt32sUsingBlock: (void (^)(uint64_t key, uint32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -5612,20 +5043,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + uint32_t unwrappedValue = [aValue unsignedIntValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -5681,39 +5114,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt32:(int32_t)value - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt32s:(const int32_t [])values - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -5785,30 +5185,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt32sUsingBlock: (void (^)(uint64_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -5819,20 +5226,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -5888,39 +5297,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64:(uint64_t)value - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -5992,30 +5368,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt64sUsingBlock: (void (^)(uint64_t key, uint64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -6026,20 +5409,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + uint64_t unwrappedValue = [aValue unsignedLongLongValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -6095,39 +5480,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt64:(int64_t)value - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt64s:(const int64_t [])values - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -6199,30 +5551,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt64sUsingBlock: (void (^)(uint64_t key, int64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue longLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue longLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -6233,20 +5592,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + int64_t unwrappedValue = [aValue longLongValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -6302,39 +5663,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithBool:(BOOL)value - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithBools:(const BOOL [])values - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -6406,30 +5734,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndBoolsUsingBlock: (void (^)(uint64_t key, BOOL value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue boolValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue boolValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -6440,20 +5775,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + BOOL unwrappedValue = [aValue boolValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -6509,39 +5846,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithFloat:(float)value - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithFloats:(const float [])values - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -6613,30 +5917,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndFloatsUsingBlock: (void (^)(uint64_t key, float value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue floatValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue floatValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -6647,20 +5958,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + float unwrappedValue = [aValue floatValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -6716,39 +6029,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithDouble:(double)value - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithDoubles:(const double [])values - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -6820,30 +6100,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndDoublesUsingBlock: (void (^)(uint64_t key, double value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue doubleValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue doubleValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -6854,20 +6141,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + double unwrappedValue = [aValue doubleValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -6926,54 +6215,6 @@ void GPBDictionaryReadEntry(id mapDictionary, @synthesize validationFunc = _validationFunc; -+ (instancetype)dictionary { - return [[[self alloc] initWithValidationFunction:NULL - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { - return [[[self alloc] initWithValidationFunction:func - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValue:(int32_t)rawValue - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:&rawValue - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t [])rawValues - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:rawValues - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(NSUInteger)numItems { - return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; } @@ -7055,30 +6296,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndRawValuesUsingBlock: (void (^)(uint64_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey unsignedLongLongValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey unsignedLongLongValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -7089,20 +6337,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (NSData *)serializedDataForUnknownValue:(int32_t)value @@ -7152,15 +6402,20 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndEnumsUsingBlock: (void (^)(uint64_t key, int32_t value, BOOL *stop))block { GPBEnumValidationFunc func = _validationFunc; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { + BOOL stop = NO; + NSEnumerator *keys = [_dictionary keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = _dictionary[aKey]; int32_t unwrapped = [aValue intValue]; if (!func(unwrapped)) { unwrapped = kGPBUnrecognizedEnumeratorValue; } - block([aKey unsignedLongLongValue], unwrapped, stop); - }]; + block([aKey unsignedLongLongValue], unwrapped, &stop); + if (stop) { + break; + } + } } - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary { @@ -7209,39 +6464,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithObject:(id)object - forKey:(uint64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithObjects:&object - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithObjects:(const id [])objects - forKeys:(const uint64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithObjects:objects - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -7317,11 +6539,17 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndObjectsUsingBlock: (void (^)(uint64_t key, id object, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - block([aKey unsignedLongLongValue], aObject, stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; + block([aKey unsignedLongLongValue], aObject, &stop); + if (stop) { + break; + } + } } - (BOOL)isInitialized { @@ -7336,34 +6564,36 @@ void GPBDictionaryReadEntry(id mapDictionary, - (instancetype)deepCopyWithZone:(NSZone *)zone { GPBUInt64ObjectDictionary *newDict = [[GPBUInt64ObjectDictionary alloc] init]; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, - GPBMessage *msg, - BOOL *stop) { - #pragma unused(stop) + NSEnumerator *keys = [_dictionary keyEnumerator]; + id aKey; + NSMutableDictionary *internalDict = newDict->_dictionary; + while ((aKey = [keys nextObject])) { + GPBMessage *msg = _dictionary[aKey]; GPBMessage *copiedMsg = [msg copyWithZone:zone]; - [newDict->_dictionary setObject:copiedMsg forKey:aKey]; + [internalDict setObject:copiedMsg forKey:aKey]; [copiedMsg release]; - }]; + } return newDict; } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -7374,20 +6604,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); + uint64_t unwrappedKey = [aKey unsignedLongLongValue]; + id unwrappedValue = aObject; + size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType); - }]; + WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -7447,39 +6679,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32:(uint32_t)value - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -7551,30 +6750,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt32sUsingBlock: (void (^)(int64_t key, uint32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue unsignedIntValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue unsignedIntValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -7585,20 +6791,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + uint32_t unwrappedValue = [aValue unsignedIntValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -7654,39 +6862,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt32:(int32_t)value - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt32s:(const int32_t [])values - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -7758,30 +6933,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt32sUsingBlock: (void (^)(int64_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -7792,20 +6974,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -7861,39 +7045,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64:(uint64_t)value - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -7965,30 +7116,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt64sUsingBlock: (void (^)(int64_t key, uint64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue unsignedLongLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue unsignedLongLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -7999,20 +7157,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + uint64_t unwrappedValue = [aValue unsignedLongLongValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -8068,39 +7228,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt64:(int64_t)value - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt64s:(const int64_t [])values - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -8172,30 +7299,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt64sUsingBlock: (void (^)(int64_t key, int64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue longLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue longLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -8206,20 +7340,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + int64_t unwrappedValue = [aValue longLongValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -8275,39 +7411,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithBool:(BOOL)value - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithBools:(const BOOL [])values - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -8379,30 +7482,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndBoolsUsingBlock: (void (^)(int64_t key, BOOL value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue boolValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue boolValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -8413,20 +7523,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + BOOL unwrappedValue = [aValue boolValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -8482,39 +7594,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithFloat:(float)value - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithFloats:(const float [])values - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -8586,30 +7665,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndFloatsUsingBlock: (void (^)(int64_t key, float value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue floatValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue floatValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -8620,20 +7706,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + float unwrappedValue = [aValue floatValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -8689,39 +7777,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithDouble:(double)value - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithDoubles:(const double [])values - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -8793,30 +7848,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndDoublesUsingBlock: (void (^)(int64_t key, double value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue doubleValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue doubleValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -8827,20 +7889,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + double unwrappedValue = [aValue doubleValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -8899,54 +7963,6 @@ void GPBDictionaryReadEntry(id mapDictionary, @synthesize validationFunc = _validationFunc; -+ (instancetype)dictionary { - return [[[self alloc] initWithValidationFunction:NULL - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { - return [[[self alloc] initWithValidationFunction:func - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValue:(int32_t)rawValue - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:&rawValue - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t [])rawValues - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:rawValues - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(NSUInteger)numItems { - return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; } @@ -9028,30 +8044,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndRawValuesUsingBlock: (void (^)(int64_t key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - block([aKey longLongValue], [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block([aKey longLongValue], [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -9062,20 +8085,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (NSData *)serializedDataForUnknownValue:(int32_t)value @@ -9125,15 +8150,20 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndEnumsUsingBlock: (void (^)(int64_t key, int32_t value, BOOL *stop))block { GPBEnumValidationFunc func = _validationFunc; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - NSNumber *aValue, - BOOL *stop) { + BOOL stop = NO; + NSEnumerator *keys = [_dictionary keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = _dictionary[aKey]; int32_t unwrapped = [aValue intValue]; if (!func(unwrapped)) { unwrapped = kGPBUnrecognizedEnumeratorValue; } - block([aKey longLongValue], unwrapped, stop); - }]; + block([aKey longLongValue], unwrapped, &stop); + if (stop) { + break; + } + } } - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary { @@ -9182,39 +8212,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithObject:(id)object - forKey:(int64_t)key { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBInt64ObjectDictionary*)[self alloc] initWithObjects:&object - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithObjects:(const id [])objects - forKeys:(const int64_t [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBInt64ObjectDictionary*)[self alloc] initWithObjects:objects - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -9290,11 +8287,17 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndObjectsUsingBlock: (void (^)(int64_t key, id object, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - block([aKey longLongValue], aObject, stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; + block([aKey longLongValue], aObject, &stop); + if (stop) { + break; + } + } } - (BOOL)isInitialized { @@ -9309,34 +8312,36 @@ void GPBDictionaryReadEntry(id mapDictionary, - (instancetype)deepCopyWithZone:(NSZone *)zone { GPBInt64ObjectDictionary *newDict = [[GPBInt64ObjectDictionary alloc] init]; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey, - GPBMessage *msg, - BOOL *stop) { - #pragma unused(stop) + NSEnumerator *keys = [_dictionary keyEnumerator]; + id aKey; + NSMutableDictionary *internalDict = newDict->_dictionary; + while ((aKey = [keys nextObject])) { + GPBMessage *msg = _dictionary[aKey]; GPBMessage *copiedMsg = [msg copyWithZone:zone]; - [newDict->_dictionary setObject:copiedMsg forKey:aKey]; + [internalDict setObject:copiedMsg forKey:aKey]; [copiedMsg release]; - }]; + } return newDict; } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -9347,20 +8352,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey, - id aObject, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSNumber *aKey; + while ((aKey = [keys nextObject])) { + id aObject = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); + int64_t unwrappedKey = [aKey longLongValue]; + id unwrappedValue = aObject; + size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType); - WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType); - }]; + WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -9420,39 +8427,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32:(uint32_t)value - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -9528,30 +8502,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt32sUsingBlock: (void (^)(NSString *key, uint32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue unsignedIntValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue unsignedIntValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -9562,20 +8543,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + uint32_t unwrappedValue = [aValue unsignedIntValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -9635,39 +8618,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt32:(int32_t)value - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt32s:(const int32_t [])values - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -9743,30 +8693,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt32sUsingBlock: (void (^)(NSString *key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -9777,20 +8734,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -9850,39 +8809,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64:(uint64_t)value - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -9958,30 +8884,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndUInt64sUsingBlock: (void (^)(NSString *key, uint64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue unsignedLongLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue unsignedLongLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -9992,20 +8925,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + uint64_t unwrappedValue = [aValue unsignedLongLongValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -10065,39 +9000,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt64:(int64_t)value - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt64s:(const int64_t [])values - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -10173,30 +9075,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndInt64sUsingBlock: (void (^)(NSString *key, int64_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue longLongValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue longLongValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -10207,20 +9116,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + int64_t unwrappedValue = [aValue longLongValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -10280,39 +9191,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithBool:(BOOL)value - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithBools:(const BOOL [])values - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -10388,30 +9266,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndBoolsUsingBlock: (void (^)(NSString *key, BOOL value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue boolValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue boolValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -10422,20 +9307,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + BOOL unwrappedValue = [aValue boolValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -10495,39 +9382,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithFloat:(float)value - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithFloats:(const float [])values - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -10603,30 +9457,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndFloatsUsingBlock: (void (^)(NSString *key, float value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue floatValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue floatValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -10637,20 +9498,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + float unwrappedValue = [aValue floatValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -10710,39 +9573,6 @@ void GPBDictionaryReadEntry(id mapDictionary, NSMutableDictionary *_dictionary; } -+ (instancetype)dictionary { - return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithDouble:(double)value - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithDoubles:(const double [])values - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -10818,30 +9648,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndDoublesUsingBlock: (void (^)(NSString *key, double value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue doubleValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue doubleValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -10852,20 +9689,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + double unwrappedValue = [aValue doubleValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (void)setGPBGenericValue:(GPBGenericValue *)value @@ -10928,54 +9767,6 @@ void GPBDictionaryReadEntry(id mapDictionary, @synthesize validationFunc = _validationFunc; -+ (instancetype)dictionary { - return [[[self alloc] initWithValidationFunction:NULL - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { - return [[[self alloc] initWithValidationFunction:func - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValue:(int32_t)rawValue - forKey:(NSString *)key { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:&rawValue - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t [])rawValues - forKeys:(const NSString * [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:rawValues - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBStringEnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(NSUInteger)numItems { - return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; } @@ -11061,30 +9852,37 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndRawValuesUsingBlock: (void (^)(NSString *key, int32_t value, BOOL *stop))block { - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - block(aKey, [aValue intValue], stop); - }]; + BOOL stop = NO; + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; + block(aKey, [aValue intValue], &stop); + if (stop) { + break; + } + } } - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { - NSUInteger count = _dictionary.count; + NSDictionary *internal = _dictionary; + NSUInteger count = internal.count; if (count == 0) { return 0; } GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; - __block size_t result = 0; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) + size_t result = 0; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; - }]; + } size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); result += tagSize * count; return result; @@ -11095,20 +9893,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBDataType valueDataType = GPBGetFieldDataType(field); GPBDataType keyDataType = field.mapKeyDataType; uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { - #pragma unused(stop) - // Write the tag. + NSDictionary *internal = _dictionary; + NSEnumerator *keys = [internal keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = internal[aKey]; [outputStream writeInt32NoTag:tag]; // Write the size of the message. - size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); - msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); + NSString *unwrappedKey = aKey; + int32_t unwrappedValue = [aValue intValue]; + size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); + msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); [outputStream writeInt32NoTag:(int32_t)msgSize]; // Write the fields. - WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType); - WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType); - }]; + WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); + WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); + } } - (NSData *)serializedDataForUnknownValue:(int32_t)value @@ -11158,15 +9958,20 @@ void GPBDictionaryReadEntry(id mapDictionary, - (void)enumerateKeysAndEnumsUsingBlock: (void (^)(NSString *key, int32_t value, BOOL *stop))block { GPBEnumValidationFunc func = _validationFunc; - [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey, - NSNumber *aValue, - BOOL *stop) { + BOOL stop = NO; + NSEnumerator *keys = [_dictionary keyEnumerator]; + NSString *aKey; + while ((aKey = [keys nextObject])) { + NSNumber *aValue = _dictionary[aKey]; int32_t unwrapped = [aValue intValue]; if (!func(unwrapped)) { unwrapped = kGPBUnrecognizedEnumeratorValue; } - block(aKey, unwrapped, stop); - }]; + block(aKey, unwrapped, &stop); + if (stop) { + break; + } + } } - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary { @@ -11230,39 +10035,6 @@ void GPBDictionaryReadEntry(id mapDictionary, BOOL _valueSet[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32:(uint32_t)value - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -11472,39 +10244,6 @@ void GPBDictionaryReadEntry(id mapDictionary, BOOL _valueSet[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt32:(int32_t)value - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt32s:(const int32_t [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -11714,39 +10453,6 @@ void GPBDictionaryReadEntry(id mapDictionary, BOOL _valueSet[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64:(uint64_t)value - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -11956,39 +10662,6 @@ void GPBDictionaryReadEntry(id mapDictionary, BOOL _valueSet[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithInt64:(int64_t)value - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithInt64s:(const int64_t [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count: - // on to get the type correct. - return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -12198,39 +10871,6 @@ void GPBDictionaryReadEntry(id mapDictionary, BOOL _valueSet[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithBool:(BOOL)value - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithBools:(const BOOL [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count: - // on to get the type correct. - return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -12440,39 +11080,6 @@ void GPBDictionaryReadEntry(id mapDictionary, BOOL _valueSet[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithFloat:(float)value - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithFloats:(const float [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count: - // on to get the type correct. - return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -12682,39 +11289,6 @@ void GPBDictionaryReadEntry(id mapDictionary, BOOL _valueSet[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithDouble:(double)value - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:&value - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithDoubles:(const double [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count: - // on to get the type correct. - return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -12923,39 +11497,6 @@ void GPBDictionaryReadEntry(id mapDictionary, id _values[2]; } -+ (instancetype)dictionary { - return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease]; -} - -+ (instancetype)dictionaryWithObject:(id)object - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBBoolObjectDictionary*)[self alloc] initWithObjects:&object - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithObjects:(const id [])objects - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count: - // on to get the type correct. - return [[(GPBBoolObjectDictionary*)[self alloc] initWithObjects:objects - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithDictionary: - // on to get the type correct. - return [[(GPBBoolObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems { - return [[[self alloc] initWithCapacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -13189,54 +11730,6 @@ void GPBDictionaryReadEntry(id mapDictionary, @synthesize validationFunc = _validationFunc; -+ (instancetype)dictionary { - return [[[self alloc] initWithValidationFunction:NULL - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func { - return [[[self alloc] initWithValidationFunction:func - rawValues:NULL - forKeys:NULL - count:0] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValue:(int32_t)rawValue - forKey:(BOOL)key { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:&rawValue - forKeys:&key - count:1] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t [])values - forKeys:(const BOOL [])keys - count:(NSUInteger)count { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func - rawValues:values - forKeys:keys - count:count] autorelease]; -} - -+ (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary { - // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count: - // on to get the type correct. - return [[(GPBBoolEnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease]; -} - -+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(NSUInteger)numItems { - return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease]; -} - - (instancetype)init { return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; } @@ -13609,14 +12102,14 @@ void GPBDictionaryReadEntry(id mapDictionary, } } -- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, +- (void)enumerateKeysAndObjectsUsingBlock:(void (NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block { [_dictionary enumerateKeysAndObjectsUsingBlock:block]; } - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(id key, + usingBlock:(void (NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block { [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; |