Skip to content

Commit

Permalink
Shrink ASImageNode by .6% and ASNetworkImageNode by 2.2% (#1487)
Browse files Browse the repository at this point in the history
* Shrink ASImageNode by .6% and ASNetworkImageNode by 2.2%

ASImageNode goes from 1384 to 1376. ASNetworkImageNode goes from 1496 to 1464.

These objects accumulate in the heap, so reducing their size will allow more to accumulate before memory warnings.

Group the `BOOL`s into a struct. Shrink the various stored `enum`s to fit the size of their contents. Move the ivars around so that the smaller `enum` are near eachother and the bitfield struct.

* add comments as requested in garrett's review.

* access ivar directly since already locked as suggested in review.
  • Loading branch information
Greg Bolsinga authored May 7, 2019
1 parent 8b70b76 commit 4d1176b
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 100 deletions.
6 changes: 3 additions & 3 deletions Source/ASImageNode+AnimatedImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ - (void)setAnimatedImagePaused:(BOOL)animatedImagePaused
{
ASLockScopeSelf();

_animatedImagePaused = animatedImagePaused;
_imageNodeFlags.animatedImagePaused = animatedImagePaused;

[self _locked_setShouldAnimate:!animatedImagePaused];
}

- (BOOL)animatedImagePaused
{
ASLockScopeSelf();
return _animatedImagePaused;
return _imageNodeFlags.animatedImagePaused;
}

- (void)setCoverImageCompleted:(UIImage *)coverImage
Expand Down Expand Up @@ -235,7 +235,7 @@ - (void)_locked_startAnimating
return;
}

if (_animatedImagePaused) {
if (_imageNodeFlags.animatedImagePaused) {
return;
}

Expand Down
20 changes: 9 additions & 11 deletions Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ @implementation ASImageNode
ASTextNode *_debugLabelNode;

// Cropping.
BOOL _cropEnabled; // Defaults to YES.
BOOL _forceUpscaling; //Defaults to NO.
CGSize _forcedSize; //Defaults to CGSizeZero, indicating no forced size.
CGRect _cropRect; // Defaults to CGRectMake(0.5, 0.5, 0, 0)
CGRect _cropDisplayBounds; // Defaults to CGRectNull
Expand All @@ -175,8 +173,8 @@ - (instancetype)init
// initial value. With setting a explicit backgroundColor we can prevent that change.
self.backgroundColor = [UIColor clearColor];

_cropEnabled = YES;
_forceUpscaling = NO;
_imageNodeFlags.cropEnabled = YES;
_imageNodeFlags.forceUpscaling = NO;
_cropRect = CGRectMake(0.5, 0.5, 0, 0);
_cropDisplayBounds = CGRectNull;
_placeholderColor = ASDisplayNodeDefaultPlaceholderColor();
Expand Down Expand Up @@ -301,8 +299,8 @@ - (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
drawParameters->_contentsScale = _contentsScaleForDisplay;
drawParameters->_backgroundColor = self.backgroundColor;
drawParameters->_contentMode = self.contentMode;
drawParameters->_cropEnabled = _cropEnabled;
drawParameters->_forceUpscaling = _forceUpscaling;
drawParameters->_cropEnabled = _imageNodeFlags.cropEnabled;
drawParameters->_forceUpscaling = _imageNodeFlags.forceUpscaling;
drawParameters->_forcedSize = _forcedSize;
drawParameters->_cropRect = _cropRect;
drawParameters->_cropDisplayBounds = _cropDisplayBounds;
Expand Down Expand Up @@ -594,7 +592,7 @@ - (void)clearContents
- (BOOL)isCropEnabled
{
AS::MutexLocker l(__instanceLock__);
return _cropEnabled;
return _imageNodeFlags.cropEnabled;
}

- (void)setCropEnabled:(BOOL)cropEnabled
Expand All @@ -605,12 +603,12 @@ - (void)setCropEnabled:(BOOL)cropEnabled
- (void)setCropEnabled:(BOOL)cropEnabled recropImmediately:(BOOL)recropImmediately inBounds:(CGRect)cropBounds
{
__instanceLock__.lock();
if (_cropEnabled == cropEnabled) {
if (_imageNodeFlags.cropEnabled == cropEnabled) {
__instanceLock__.unlock();
return;
}

_cropEnabled = cropEnabled;
_imageNodeFlags.cropEnabled = cropEnabled;
_cropDisplayBounds = cropBounds;

UIImage *image = _image;
Expand Down Expand Up @@ -660,13 +658,13 @@ - (void)setCropRect:(CGRect)cropRect
- (BOOL)forceUpscaling
{
AS::MutexLocker l(__instanceLock__);
return _forceUpscaling;
return _imageNodeFlags.forceUpscaling;
}

- (void)setForceUpscaling:(BOOL)forceUpscaling
{
AS::MutexLocker l(__instanceLock__);
_forceUpscaling = forceUpscaling;
_imageNodeFlags.forceUpscaling = forceUpscaling;
}

- (CGSize)forcedSize
Expand Down
Loading

0 comments on commit 4d1176b

Please sign in to comment.