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 _ASCollectionPendingState from 144 to 128 bytes, a 12.5% reduction #1485

Merged
merged 3 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
141 changes: 134 additions & 7 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
@interface _ASCollectionPendingState : NSObject {
@public
std::vector<std::vector<ASRangeTuningParameters>> _tuningParameters;

// Keep these enums by the bitfield struct to save memory.
ASLayoutRangeMode _rangeMode;
ASCellLayoutMode _cellLayoutMode;
struct {
unsigned int allowsSelection:1; // default is YES
unsigned int allowsMultipleSelection:1; // default is NO
unsigned int inverted:1; //default is NO
unsigned int alwaysBounceVertical:1;
unsigned int alwaysBounceHorizontal:1;
unsigned int animatesContentOffset:1;
unsigned int showsVerticalScrollIndicator:1;
unsigned int showsHorizontalScrollIndicator:1;
unsigned int pagingEnabled:1;
} _flags;
}
@property (nonatomic, weak) id <ASCollectionDelegate> delegate;
@property (nonatomic, weak) id <ASCollectionDataSource> dataSource;
Expand Down Expand Up @@ -65,19 +80,131 @@ - (instancetype)init
if (self) {
_rangeMode = ASLayoutRangeModeUnspecified;
_tuningParameters = [ASAbstractLayoutController defaultTuningParameters];
_allowsSelection = YES;
_allowsMultipleSelection = NO;
_inverted = NO;
_flags.allowsSelection = YES;
_flags.allowsMultipleSelection = NO;
_flags.inverted = NO;
_contentInset = UIEdgeInsetsZero;
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
_showsVerticalScrollIndicator = YES;
_showsHorizontalScrollIndicator = YES;
_pagingEnabled = NO;
_flags.animatesContentOffset = NO;
_flags.showsVerticalScrollIndicator = YES;
_flags.showsHorizontalScrollIndicator = YES;
_flags.pagingEnabled = NO;
}
return self;
}

#pragma mark Properties

- (ASLayoutRangeMode)rangeMode
{
return _rangeMode;
}

- (void)setRangeMode:(ASLayoutRangeMode)rangeMode
{
_rangeMode = rangeMode;
}

- (ASCellLayoutMode)cellLayoutMode
{
return _cellLayoutMode;
}

- (void)setCellLayoutMode:(ASCellLayoutMode)cellLayoutMode
{
_cellLayoutMode = cellLayoutMode;
}

- (BOOL)allowsSelection
{
return _flags.allowsSelection;
}

- (void)setAllowsSelection:(BOOL)allowsSelection
{
_flags.allowsSelection = allowsSelection;
}

- (BOOL)allowsMultipleSelection
{
return _flags.allowsMultipleSelection;
}

- (void)setAllowsMultipleSelection:(BOOL)allowsMultipleSelection
{
_flags.allowsMultipleSelection = allowsMultipleSelection;
}

- (BOOL)inverted
{
return _flags.inverted;
}

-(void)setInverted:(BOOL)inverted
{
_flags.inverted = inverted;
}

-(BOOL)alwaysBounceVertical
{
return _flags.alwaysBounceVertical;
}

-(void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical
{
_flags.alwaysBounceVertical = alwaysBounceVertical;
}

-(BOOL)alwaysBounceHorizontal
{
return _flags.alwaysBounceHorizontal;
}

-(void)setAlwaysBounceHorizontal:(BOOL)alwaysBounceHorizontal
{
_flags.alwaysBounceHorizontal = alwaysBounceHorizontal;
}

- (BOOL)animatesContentOffset
{
return _flags.animatesContentOffset;
}

-(void)setAnimatesContentOffset:(BOOL)animatesContentOffset
{
_flags.animatesContentOffset = animatesContentOffset;
}

- (BOOL)showsVerticalScrollIndicator
{
return _flags.showsVerticalScrollIndicator;
}

- (void)setShowsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator
{
_flags.showsVerticalScrollIndicator = showsVerticalScrollIndicator;
}

-(BOOL)showsHorizontalScrollIndicator
{
return _flags.showsHorizontalScrollIndicator;
}

- (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
{
_flags.showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;
}

-(BOOL)pagingEnabled
{
return _flags.pagingEnabled;
}

- (void)setPagingEnabled:(BOOL)pagingEnabled
{
_flags.pagingEnabled = pagingEnabled;
}

#pragma mark Tuning Parameters

- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
Expand Down
2 changes: 1 addition & 1 deletion Source/ASCollectionViewProtocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/ASBaseDefines.h>

typedef NS_OPTIONS(NSUInteger, ASCellLayoutMode) {
typedef NS_OPTIONS(unsigned short, ASCellLayoutMode) {
/**
* No options set. If cell layout mode is set to ASCellLayoutModeNone, the default values for
* each flag listed below is used.
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASLayoutRangeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ AS_EXTERN BOOL ASRangeTuningParametersEqualToRangeTuningParameters(ASRangeTuning
* Depending on some conditions (including interface state and direction of the scroll view, state of rendering engine, etc),
* a range controller can choose which mode it should use at a given time.
*/
typedef NS_ENUM(NSInteger, ASLayoutRangeMode) {
typedef NS_ENUM(char, ASLayoutRangeMode) {
ASLayoutRangeModeUnspecified = -1,

/**
Expand Down