Simplify getter/setter method implementations

Remove unnecessary retain/releases for GPBFieldDescriptors when
creating implementations with blocks. The descriptors do not need
to be memory managed because they are essentially global constructs
that are guaranteed to be around the lifetime of the app.
This commit is contained in:
Dave MacLachlan 2017-11-14 15:58:22 -08:00
parent 91ff83c024
commit 949596ea32

View File

@ -2998,7 +2998,7 @@ typedef struct ResolveIvarAccessorMethodResult {
SEL encodingSelector; SEL encodingSelector;
} ResolveIvarAccessorMethodResult; } ResolveIvarAccessorMethodResult;
static void ResolveIvarGet(GPBFieldDescriptor *field, static void ResolveIvarGet(__unsafe_unretained GPBFieldDescriptor *field,
ResolveIvarAccessorMethodResult *result) { ResolveIvarAccessorMethodResult *result) {
GPBDataType fieldDataType = GPBGetFieldDataType(field); GPBDataType fieldDataType = GPBGetFieldDataType(field);
switch (fieldDataType) { switch (fieldDataType) {
@ -3040,7 +3040,7 @@ static void ResolveIvarGet(GPBFieldDescriptor *field,
} }
} }
static void ResolveIvarSet(GPBFieldDescriptor *field, static void ResolveIvarSet(__unsafe_unretained GPBFieldDescriptor *field,
GPBFileSyntax syntax, GPBFileSyntax syntax,
ResolveIvarAccessorMethodResult *result) { ResolveIvarAccessorMethodResult *result) {
GPBDataType fieldDataType = GPBGetFieldDataType(field); GPBDataType fieldDataType = GPBGetFieldDataType(field);
@ -3086,7 +3086,12 @@ static void ResolveIvarSet(GPBFieldDescriptor *field,
// no need for checks here to see if has*/setHas* are allowed. // no need for checks here to see if has*/setHas* are allowed.
ResolveIvarAccessorMethodResult result = {NULL, NULL}; ResolveIvarAccessorMethodResult result = {NULL, NULL};
for (GPBFieldDescriptor *field in descriptor->fields_) {
// |field| can be __unsafe_unretained because they are created at startup
// and are essentially global. No need to pay for retain/release when
// they are captured in blocks.
for (__unsafe_unretained GPBFieldDescriptor *field in descriptor->fields_) {
BOOL isMapOrArray = GPBFieldIsMapOrArray(field); BOOL isMapOrArray = GPBFieldIsMapOrArray(field);
if (!isMapOrArray) { if (!isMapOrArray) {
// Single fields. // Single fields.