Skip to content

Commit

Permalink
Don't copy onDidLoadBlocks #trivial (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adlai-Holler committed Sep 17, 2018
1 parent bf8d268 commit fa8da15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,7 @@ - (void)_didLoad
[self didLoad];

__instanceLock__.lock();
NSArray *onDidLoadBlocks = [_onDidLoadBlocks copy];
_onDidLoadBlocks = nil;
let onDidLoadBlocks = ASTransferStrong(_onDidLoadBlocks);
__instanceLock__.unlock();

for (ASDisplayNodeDidLoadBlock block in onDidLoadBlocks) {
Expand Down
17 changes: 16 additions & 1 deletion Source/Base/ASBaseDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//

#import <Foundation/NSObjCRuntime.h>
#import <Foundation/Foundation.h>

#define AS_EXTERN FOUNDATION_EXTERN
#define unowned __unsafe_unretained
Expand Down Expand Up @@ -229,3 +229,18 @@
} \
__result; \
})

/**
* Capture-and-clear a strong reference without the intervening retain/release pair.
*
* E.g. let localVar = ASTransferStrong(_myIvar);
* Post-condition: localVar has the strong value from _myIvar and _myIvar is nil.
* No retain/release is emitted when the optimizer is on.
*/
#define ASTransferStrong(lvalue) ({ \
CFTypeRef *__rawPtr = (CFTypeRef *)(void *)(&(lvalue)); \
CFTypeRef __cfValue = *__rawPtr; \
*__rawPtr = NULL; \
__typeof(lvalue) __result = (__bridge_transfer __typeof(lvalue))__cfValue; \
__result; \
})

0 comments on commit fa8da15

Please sign in to comment.