Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink ASDisplayNode from 1072 to 968 bytes, reduction of 10.74% #1484

Merged
merged 2 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ASDisplayNode+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ AS_EXTERN void ASPerformBlockOnBackgroundThread(void (^block)(void)); // DISPATC
/**
* Bitmask to indicate what performance measurements the cell should record.
*/
typedef NS_OPTIONS(NSUInteger, ASDisplayNodePerformanceMeasurementOptions) {
typedef NS_OPTIONS(unsigned char, ASDisplayNodePerformanceMeasurementOptions) {
ASDisplayNodePerformanceMeasurementOptionLayoutSpec = 1 << 0,
ASDisplayNodePerformanceMeasurementOptionLayoutComputation = 1 << 1
};
Expand Down
2 changes: 1 addition & 1 deletion Source/ASDisplayNode+InterfaceState.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* The defualt state, ASInterfaceStateNone, means that the element is not predicted to be onscreen soon and
* preloading should not be performed. Swift: use [] for the default behavior.
*/
typedef NS_OPTIONS(NSUInteger, ASInterfaceState)
typedef NS_OPTIONS(unsigned char, ASInterfaceState)
{
/** The element is not predicted to be onscreen soon and preloading should not be performed */
ASInterfaceStateNone = 0,
Expand Down
6 changes: 3 additions & 3 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@ @implementation ASDisplayNode (ASAutomaticSubnodeManagement)
- (BOOL)automaticallyManagesSubnodes
{
MutexLocker l(__instanceLock__);
return _automaticallyManagesSubnodes;
return _flags.automaticallyManagesSubnodes;
}

- (void)setAutomaticallyManagesSubnodes:(BOOL)automaticallyManagesSubnodes
{
MutexLocker l(__instanceLock__);
_automaticallyManagesSubnodes = automaticallyManagesSubnodes;
_flags.automaticallyManagesSubnodes = automaticallyManagesSubnodes;
}

@end
Expand Down Expand Up @@ -1027,7 +1027,7 @@ - (void)_pendingLayoutTransitionDidComplete
// We generate placeholders at -layoutThatFits: time so that a node is guaranteed to have a placeholder ready to go.
// This is also because measurement is usually asynchronous, but placeholders need to be set up synchronously.
// First measurement is guaranteed to be before the node is onscreen, so we can create the image async. but still have it appear sync.
if (_placeholderEnabled && !_placeholderImage && [self _locked_displaysAsynchronously]) {
if (_flags.placeholderEnabled && !_placeholderImage && [self _locked_displaysAsynchronously]) {

// Zero-sized nodes do not require a placeholder.
CGSize layoutSize = _calculatedDisplayNodeLayout.layout.size;
Expand Down
4 changes: 2 additions & 2 deletions Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ - (ASLayout *)yogaCalculatedLayout
}

- (BOOL)willApplyNextYogaCalculatedLayout {
return _willApplyNextYogaCalculatedLayout;
return _flags.willApplyNextYogaCalculatedLayout;
}

- (void)setWillApplyNextYogaCalculatedLayout:(BOOL)willApplyNextYogaCalculatedLayout {
_willApplyNextYogaCalculatedLayout = willApplyNextYogaCalculatedLayout;
_flags.willApplyNextYogaCalculatedLayout = willApplyNextYogaCalculatedLayout;
}

- (void)setYogaLayoutInProgress:(BOOL)yogaLayoutInProgress
Expand Down
2 changes: 1 addition & 1 deletion Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef ASLayoutSpec * _Nonnull(^ASLayoutSpecBlock)(__kindof ASDisplayNode *node
*/
typedef void (^ASDisplayNodeNonFatalErrorBlock)(NSError *error);

typedef NS_ENUM(NSInteger, ASCornerRoundingType) {
typedef NS_ENUM(unsigned char, ASCornerRoundingType) {
ASCornerRoundingTypeDefaultSlowCALayer,
ASCornerRoundingTypePrecomposited,
ASCornerRoundingTypeClipping
Expand Down
34 changes: 17 additions & 17 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ - (void)_initializeInstance
_flags.canCallSetNeedsDisplayOfLayer = YES;

_fallbackSafeAreaInsets = UIEdgeInsetsZero;
_fallbackInsetsLayoutMarginsFromSafeArea = YES;
_isViewControllerRoot = NO;
_flags.fallbackInsetsLayoutMarginsFromSafeArea = YES;
_flags.isViewControllerRoot = NO;

_automaticallyRelayoutOnSafeAreaChanges = NO;
_automaticallyRelayoutOnLayoutMarginsChanges = NO;
_flags.automaticallyRelayoutOnSafeAreaChanges = NO;
_flags.automaticallyRelayoutOnLayoutMarginsChanges = NO;

[self baseDidInit];
}
Expand Down Expand Up @@ -861,37 +861,37 @@ - (void)_fallbackUpdateSafeAreaOnChildren
- (BOOL)isViewControllerRoot
{
MutexLocker l(__instanceLock__);
return _isViewControllerRoot;
return _flags.isViewControllerRoot;
}

- (void)setViewControllerRoot:(BOOL)flag
{
MutexLocker l(__instanceLock__);
_isViewControllerRoot = flag;
_flags.isViewControllerRoot = flag;
}

- (BOOL)automaticallyRelayoutOnSafeAreaChanges
{
MutexLocker l(__instanceLock__);
return _automaticallyRelayoutOnSafeAreaChanges;
return _flags.automaticallyRelayoutOnSafeAreaChanges;
}

- (void)setAutomaticallyRelayoutOnSafeAreaChanges:(BOOL)flag
{
MutexLocker l(__instanceLock__);
_automaticallyRelayoutOnSafeAreaChanges = flag;
_flags.automaticallyRelayoutOnSafeAreaChanges = flag;
}

- (BOOL)automaticallyRelayoutOnLayoutMarginsChanges
{
MutexLocker l(__instanceLock__);
return _automaticallyRelayoutOnLayoutMarginsChanges;
return _flags.automaticallyRelayoutOnLayoutMarginsChanges;
}

- (void)setAutomaticallyRelayoutOnLayoutMarginsChanges:(BOOL)flag
{
MutexLocker l(__instanceLock__);
_automaticallyRelayoutOnLayoutMarginsChanges = flag;
_flags.automaticallyRelayoutOnLayoutMarginsChanges = flag;
}

- (void)__setNodeController:(ASNodeController *)controller
Expand Down Expand Up @@ -2593,7 +2593,7 @@ - (void)_locked_layoutPlaceholderIfNecessary
- (BOOL)_locked_shouldHavePlaceholderLayer
{
DISABLED_ASAssertLocked(__instanceLock__);
return (_placeholderEnabled && [self _implementsDisplay]);
return (_flags.placeholderEnabled && [self _implementsDisplay]);
}

- (void)_locked_setupPlaceholderLayerIfNeeded
Expand Down Expand Up @@ -2638,13 +2638,13 @@ - (BOOL)placeholderShouldPersist
- (BOOL)placeholderEnabled
{
MutexLocker l(__instanceLock__);
return _placeholderEnabled;
return _flags.placeholderEnabled;
}

- (void)setPlaceholderEnabled:(BOOL)placeholderEnabled
{
MutexLocker l(__instanceLock__);
_placeholderEnabled = placeholderEnabled;
_flags.placeholderEnabled = placeholderEnabled;
}

- (NSTimeInterval)placeholderFadeDuration
Expand Down Expand Up @@ -3144,7 +3144,7 @@ - (BOOL)shouldScheduleDisplayWithNewInterfaceState:(ASInterfaceState)newInterfac
- (void)addInterfaceStateDelegate:(id <ASInterfaceStateDelegate>)interfaceStateDelegate
{
MutexLocker l(__instanceLock__);
_hasHadInterfaceStateDelegates = YES;
_flags.hasHadInterfaceStateDelegates = YES;
for (int i = 0; i < AS_MAX_INTERFACE_STATE_DELEGATES; i++) {
if (_interfaceStateDelegates[i] == nil) {
_interfaceStateDelegates[i] = interfaceStateDelegate;
Expand Down Expand Up @@ -3326,7 +3326,7 @@ - (void)enumerateInterfaceStateDelegates:(void (NS_NOESCAPE ^)(id<ASInterfaceSta
{
ASLockScopeSelf();
// Fast path for non-delegating nodes.
if (!_hasHadInterfaceStateDelegates) {
if (!_flags.hasHadInterfaceStateDelegates) {
return;
}

Expand Down Expand Up @@ -3538,13 +3538,13 @@ - (ASDisplayNodePerformanceMeasurements)performanceMeasurements
- (void)setIsAccessibilityContainer:(BOOL)isAccessibilityContainer
{
MutexLocker l(__instanceLock__);
_isAccessibilityContainer = isAccessibilityContainer;
_flags.isAccessibilityContainer = isAccessibilityContainer;
}

- (BOOL)isAccessibilityContainer
{
MutexLocker l(__instanceLock__);
return _isAccessibilityContainer;
return _flags.isAccessibilityContainer;
}

- (NSString *)defaultAccessibilityLabel
Expand Down
2 changes: 1 addition & 1 deletion Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor
{
ASLockScopeSelf();
if (ASCompareAssignCopy(_placeholderColor, placeholderColor)) {
_placeholderEnabled = (placeholderColor != nil);
_flags.placeholderEnabled = (placeholderColor != nil);
}
}

Expand Down
7 changes: 1 addition & 6 deletions Source/Private/ASDisplayNode+FrameworkPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
cancelled below the point they are enabled. They continue to the leaves of the hierarchy.
*/

typedef NS_OPTIONS(NSUInteger, ASHierarchyState)
typedef NS_OPTIONS(unsigned char, ASHierarchyState)
{
/** The node may or may not have a supernode, but no supernode has a special hierarchy-influencing option enabled. */
ASHierarchyStateNormal = 0,
Expand Down Expand Up @@ -115,11 +115,6 @@ __unused static NSString * _Nonnull NSStringFromASHierarchyStateChange(ASHierarc
#undef HIERARCHY_STATE_DELTA

@interface ASDisplayNode () <ASDescriptionProvider, ASDebugDescriptionProvider>
{
@protected
ASInterfaceState _interfaceState;
ASHierarchyState _hierarchyState;
}

// The view class to use when creating a new display node instance. Defaults to _ASDisplayView.
+ (Class)viewClass;
Expand Down
20 changes: 10 additions & 10 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ - (void)setInsetsLayoutMarginsFromSafeArea:(BOOL)insetsLayoutMarginsFromSafeArea
{
_bridge_prologue_write;

_fallbackInsetsLayoutMarginsFromSafeArea = insetsLayoutMarginsFromSafeArea;
_flags.fallbackInsetsLayoutMarginsFromSafeArea = insetsLayoutMarginsFromSafeArea;

if (AS_AVAILABLE_IOS(11.0)) {
if (!_flags.layerBacked) {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ - (BOOL)_locked_insetsLayoutMarginsFromSafeArea
return _getFromViewOnly(insetsLayoutMarginsFromSafeArea);
}
}
return _fallbackInsetsLayoutMarginsFromSafeArea;
return _flags.fallbackInsetsLayoutMarginsFromSafeArea;
}

@end
Expand Down Expand Up @@ -1056,13 +1056,13 @@ @implementation ASDisplayNode (UIViewBridgeAccessibility)
- (BOOL)isAccessibilityElement
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_isAccessibilityElement, isAccessibilityElement);
return _getAccessibilityFromViewOrProperty(_flags.isAccessibilityElement, isAccessibilityElement);
}

- (void)setIsAccessibilityElement:(BOOL)isAccessibilityElement
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_isAccessibilityElement, isAccessibilityElement, isAccessibilityElement, isAccessibilityElement);
_setAccessibilityToViewAndProperty(_flags.isAccessibilityElement, isAccessibilityElement, isAccessibilityElement, isAccessibilityElement);
}

- (NSString *)accessibilityLabel
Expand Down Expand Up @@ -1192,37 +1192,37 @@ - (void)setAccessibilityLanguage:(NSString *)accessibilityLanguage
- (BOOL)accessibilityElementsHidden
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_accessibilityElementsHidden, accessibilityElementsHidden);
return _getAccessibilityFromViewOrProperty(_flags.accessibilityElementsHidden, accessibilityElementsHidden);
}

- (void)setAccessibilityElementsHidden:(BOOL)accessibilityElementsHidden
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden);
_setAccessibilityToViewAndProperty(_flags.accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden, accessibilityElementsHidden);
}

- (BOOL)accessibilityViewIsModal
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_accessibilityViewIsModal, accessibilityViewIsModal);
return _getAccessibilityFromViewOrProperty(_flags.accessibilityViewIsModal, accessibilityViewIsModal);
}

- (void)setAccessibilityViewIsModal:(BOOL)accessibilityViewIsModal
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal);
_setAccessibilityToViewAndProperty(_flags.accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal, accessibilityViewIsModal);
}

- (BOOL)shouldGroupAccessibilityChildren
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
return _getAccessibilityFromViewOrProperty(_flags.shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
}

- (void)setShouldGroupAccessibilityChildren:(BOOL)shouldGroupAccessibilityChildren
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
_setAccessibilityToViewAndProperty(_flags.shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren, shouldGroupAccessibilityChildren);
}

- (NSString *)accessibilityIdentifier
Expand Down
Loading