Skip to content

Commit

Permalink
Reuse interface state delegates when calling out #trivial (#1099)
Browse files Browse the repository at this point in the history
* Reuse interface state delegates when calling out instead of always copying
  • Loading branch information
Adlai-Holler authored and appleguy committed Sep 6, 2018
1 parent 6b0d57e commit 395fbd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ - (void)dealloc

#define ASDisplayNodeCallInterfaceStateDelegates(method) \
__instanceLock__.lock(); \
NSHashTable *delegates = [_interfaceStateDelegates copy]; \
NSHashTable *delegates = _copiedInterfaceStateDelegates; \
if (!delegates) { \
delegates = _copiedInterfaceStateDelegates = [_interfaceStateDelegates copy]; \
} \
__instanceLock__.unlock(); \
for (id <ASInterfaceStateDelegate> delegate in delegates) { \
if ([delegate respondsToSelector:@selector(method)]) { \
Expand Down Expand Up @@ -3238,12 +3241,14 @@ - (void)addInterfaceStateDelegate:(id <ASInterfaceStateDelegate>)interfaceStateD
if (_interfaceStateDelegates == nil) {
_interfaceStateDelegates = [NSHashTable weakObjectsHashTable];
}
_copiedInterfaceStateDelegates = nil;
[_interfaceStateDelegates addObject:interfaceStateDelegate];
}

- (void)removeInterfaceStateDelegate:(id <ASInterfaceStateDelegate>)interfaceStateDelegate
{
ASDN::MutexLocker l(__instanceLock__);
_copiedInterfaceStateDelegates = nil;
[_interfaceStateDelegates removeObject:interfaceStateDelegate];
}

Expand Down
4 changes: 4 additions & 0 deletions Source/Private/ASDisplayNodeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ AS_EXTERN NSString * const ASRenderingEngineDidDisplayNodesScheduledBeforeTimest
#endif

NSHashTable <id <ASInterfaceStateDelegate>> *_interfaceStateDelegates;

// never mutated, used to enumerate delegates outside of lock.
// set to nil when mutating _interfaceStateDelegates.
NSHashTable <id <ASInterfaceStateDelegate>> *_copiedInterfaceStateDelegates;
}

+ (void)scheduleNodeForRecursiveDisplay:(ASDisplayNode *)node;
Expand Down

0 comments on commit 395fbd1

Please sign in to comment.