diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 16:26:16 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 16:26:16 -0700 |
commit | 3af881c7e2db0553207876acbdb91c6e77974e44 (patch) | |
tree | 35e2a96cce802d4235bd29afa396e28ead892fa2 /objectivec/GPBExtensionRegistry.m | |
parent | 86975301f1876ce1934612777b8ca6c76520f5cc (diff) | |
parent | 942a29cecd36f2a4b22fdd2179635cd548e6bd27 (diff) | |
download | protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.tar.gz protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.tar.bz2 protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.zip |
Merge master into 3.4.x
Diffstat (limited to 'objectivec/GPBExtensionRegistry.m')
-rw-r--r-- | objectivec/GPBExtensionRegistry.m | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/objectivec/GPBExtensionRegistry.m b/objectivec/GPBExtensionRegistry.m index 65534b67..b056a52d 100644 --- a/objectivec/GPBExtensionRegistry.m +++ b/objectivec/GPBExtensionRegistry.m @@ -57,14 +57,16 @@ - (instancetype)copyWithZone:(NSZone *)zone { GPBExtensionRegistry *result = [[[self class] allocWithZone:zone] init]; - if (result && mutableClassMap_.count) { - [result->mutableClassMap_ addEntriesFromDictionary:mutableClassMap_]; - } + [result addExtensions:self]; return result; } -- (CFMutableDictionaryRef)extensionMapForContainingMessageClass: - (Class)containingMessageClass { +- (void)addExtension:(GPBExtensionDescriptor *)extension { + if (extension == nil) { + return; + } + + Class containingMessageClass = extension.containingMessageClass; CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) [mutableClassMap_ objectForKey:containingMessageClass]; if (extensionMap == nil) { @@ -74,18 +76,9 @@ &kCFTypeDictionaryValueCallBacks); [mutableClassMap_ setObject:(id)extensionMap forKey:(id<NSCopying>)containingMessageClass]; + CFRelease(extensionMap); } - return extensionMap; -} -- (void)addExtension:(GPBExtensionDescriptor *)extension { - if (extension == nil) { - return; - } - - Class containingMessageClass = extension.containingMessageClass; - CFMutableDictionaryRef extensionMap = - [self extensionMapForContainingMessageClass:containingMessageClass]; ssize_t key = extension.fieldNumber; CFDictionarySetValue(extensionMap, (const void *)key, extension); } @@ -119,10 +112,16 @@ static void CopyKeyValue(const void *key, const void *value, void *context) { Class containingMessageClass = key; CFMutableDictionaryRef otherExtensionMap = (CFMutableDictionaryRef)value; - CFMutableDictionaryRef extensionMap = - [self extensionMapForContainingMessageClass:containingMessageClass]; - - CFDictionaryApplyFunction(otherExtensionMap, CopyKeyValue, extensionMap); + CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) + [mutableClassMap_ objectForKey:containingMessageClass]; + if (extensionMap == nil) { + extensionMap = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, otherExtensionMap); + [mutableClassMap_ setObject:(id)extensionMap + forKey:(id<NSCopying>)containingMessageClass]; + CFRelease(extensionMap); + } else { + CFDictionaryApplyFunction(otherExtensionMap, CopyKeyValue, extensionMap); + } }]; } |