diff options
author | Dave MacLachlan <dmaclach@gmail.com> | 2017-11-14 15:58:22 -0800 |
---|---|---|
committer | Dave MacLachlan <dmaclach@gmail.com> | 2017-11-14 15:58:22 -0800 |
commit | 949596ea328978b4af38657d8831292b62b24686 (patch) | |
tree | efe661e63b39ed96730c1ea20bacad2af06c6c34 /objectivec/GPBMessage.m | |
parent | 91ff83c024be36e2f2728c30cd7eedcec9220d1a (diff) | |
download | protobuf-949596ea328978b4af38657d8831292b62b24686.tar.gz protobuf-949596ea328978b4af38657d8831292b62b24686.tar.bz2 protobuf-949596ea328978b4af38657d8831292b62b24686.zip |
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.
Diffstat (limited to 'objectivec/GPBMessage.m')
-rw-r--r-- | objectivec/GPBMessage.m | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index afe39c1e..649ed8a6 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -2998,7 +2998,7 @@ typedef struct ResolveIvarAccessorMethodResult { SEL encodingSelector; } ResolveIvarAccessorMethodResult; -static void ResolveIvarGet(GPBFieldDescriptor *field, +static void ResolveIvarGet(__unsafe_unretained GPBFieldDescriptor *field, ResolveIvarAccessorMethodResult *result) { GPBDataType fieldDataType = GPBGetFieldDataType(field); 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, ResolveIvarAccessorMethodResult *result) { 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. 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); if (!isMapOrArray) { // Single fields. |