[ASDisplayNode:UIViewBridge] Reduce calls to -isNodeLoaded

This commit is contained in:
Adlai Holler
2016-02-21 10:10:04 -08:00
parent e1bf0f6a88
commit 3ff833c4f5
2 changed files with 32 additions and 32 deletions

View File

@@ -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:

View File

@@ -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;