From 3ff833c4f52010c2ab97e5b52f9142f8339f02b2 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Sun, 21 Feb 2016 10:10:04 -0800 Subject: [PATCH] [ASDisplayNode:UIViewBridge] Reduce calls to -isNodeLoaded --- .../Private/ASDisplayNode+UIViewBridge.mm | 8 +-- .../Private/ASDisplayNodeInternal.h | 56 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm b/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm index 41a315ef23..4a5c02fd97 100644 --- a/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm +++ b/AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm @@ -37,7 +37,7 @@ #define DISPLAYNODE_USE_LOCKS 1 -#define __loaded (_layer != nil) +#define __loaded (_view != nil || (_layer != nil && _flags.layerBacked)) #if DISPLAYNODE_USE_LOCKS #define _bridge_prologue_read ASDN::MutexLocker l(_propertyLock); ASDisplayNodeAssertThreadAffinity(self) @@ -53,10 +53,10 @@ /// This function must be called with the node's lock already held (after _bridge_prologue_write). ASDISPLAYNODE_INLINE BOOL ASDisplayNodeShouldApplyBridgedWriteToView(ASDisplayNode *node) { if (ASDisplayNodeThreadIsMain()) { - return node.nodeLoaded; + return (node->_view != nil || (node->_layer != nil && node->_flags.layerBacked)); } else { if (node.nodeLoaded && !node->_pendingViewState.hasChanges) { - [ASPendingStateController.sharedInstance registerNode:node]; + [[ASPendingStateController sharedInstance] registerNode:node]; } return NO; } @@ -235,7 +235,7 @@ if (shouldApply) { _layer.layerProperty = (layerValueExpr); } else { ASDisplayNo _bridge_prologue_write; BOOL setFrameDirectly = _flags.synchronous && !_flags.layerBacked; BOOL isMainThread = ASDisplayNodeThreadIsMain(); - BOOL nodeLoaded = self.nodeLoaded; + BOOL nodeLoaded = __loaded; if (nodeLoaded && isMainThread && setFrameDirectly) { // For classes like ASTableNode, ASCollectionNode, ASScrollNode and similar - make sure UIView gets setFrame: diff --git a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h index 14f2f8a889..8a3aa97b80 100644 --- a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h +++ b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h @@ -55,10 +55,37 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo @package _ASPendingState *_pendingViewState; -@protected // Protects access to _view, _layer, _pendingViewState, _subnodes, _supernode, and other properties which are accessed from multiple threads. ASDN::RecursiveMutex _propertyLock; + UIView *_view; + CALayer *_layer; + struct ASDisplayNodeFlags { + // public properties + unsigned synchronous:1; + unsigned layerBacked:1; + unsigned displaysAsynchronously:1; + unsigned shouldRasterizeDescendants:1; + unsigned shouldBypassEnsureDisplay:1; + unsigned displaySuspended:1; + unsigned hasCustomDrawingPriority:1; + + // whether custom drawing is enabled + unsigned implementsInstanceDrawRect:1; + unsigned implementsDrawRect:1; + unsigned implementsInstanceImageDisplay:1; + unsigned implementsImageDisplay:1; + unsigned implementsDrawParameters:1; + + // internal state + unsigned isMeasured:1; + unsigned isEnteringHierarchy:1; + unsigned isExitingHierarchy:1; + unsigned isInHierarchy:1; + unsigned visibilityNotificationsDisabled:VISIBILITY_NOTIFICATIONS_DISABLED_BITS; + } _flags; + +@protected ASDisplayNode * __weak _supernode; ASSentinel *_displaySentinel; @@ -89,39 +116,12 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo ASDisplayNodeDidLoadBlock _nodeLoadedBlock; Class _viewClass; Class _layerClass; - UIView *_view; - CALayer *_layer; UIImage *_placeholderImage; CALayer *_placeholderLayer; // keeps track of nodes/subnodes that have not finished display, used with placeholders NSMutableSet *_pendingDisplayNodes; - - struct ASDisplayNodeFlags { - // public properties - unsigned synchronous:1; - unsigned layerBacked:1; - unsigned displaysAsynchronously:1; - unsigned shouldRasterizeDescendants:1; - unsigned shouldBypassEnsureDisplay:1; - unsigned displaySuspended:1; - unsigned hasCustomDrawingPriority:1; - - // whether custom drawing is enabled - unsigned implementsInstanceDrawRect:1; - unsigned implementsDrawRect:1; - unsigned implementsInstanceImageDisplay:1; - unsigned implementsImageDisplay:1; - unsigned implementsDrawParameters:1; - - // internal state - unsigned isMeasured:1; - unsigned isEnteringHierarchy:1; - unsigned isExitingHierarchy:1; - unsigned isInHierarchy:1; - unsigned visibilityNotificationsDisabled:VISIBILITY_NOTIFICATIONS_DISABLED_BITS; - } _flags; ASDisplayNodeExtraIvars _extra;