Skip to content

Commit afa4d09

Browse files
authored
Avoid unnecessary copy of noz_defer block
The block passed to `noz_defer` is guaranteed to be non-escaping and thus always available on the stack at the point that defer triggers. This means we can use `__unsafe_unretained` to avoid an unnecessary `copy` of the block to the heap by ARC as an optimization.
1 parent 827841c commit afa4d09

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ZipUtilities/NOZ_Project.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
return YES; // fclose will auto happen
7171
*/
7272
#define noz_defer(deferBlock) \
73-
__strong noz_defer_block_t noz_macro_concat(__noz_stack_defer_block_, __LINE__) __attribute__((cleanup(noz_deferFunc), unused)) = deferBlock
73+
__unsafe_unretained noz_defer_block_t noz_macro_concat(__noz_stack_defer_block_, __LINE__) __attribute__((cleanup(noz_deferFunc), unused)) = deferBlock
7474

7575
typedef void(^noz_defer_block_t)(void);
76-
NS_INLINE void noz_deferFunc(__strong noz_defer_block_t __nonnull * __nonnull blockRef)
76+
NS_INLINE void noz_deferFunc(__unsafe_unretained noz_defer_block_t __nonnull * __nonnull blockRef)
7777
{
78-
noz_defer_block_t actualBlock = *blockRef;
78+
__unsafe_unretained noz_defer_block_t actualBlock = *blockRef;
7979
actualBlock();
8080
}
8181

0 commit comments

Comments
 (0)